我知道这是一个简单的问题,但我做不到。我必须做两件事。其中之一是管理程序,它将管理程序,例如停止、暂停、恢复。另一件事只会显示日志。所以我需要 2 个控制台。
如何打开两个控制台?
如何将日志从管理控制台传递到日志记录控制台。示例代码如下:
if __name__ == '__main__':
try:
while True:
initialmyProgram()
print('Please press \'1\' key to stop program..\n')
print('Please press \'5\' key to resume program..\n')
print('Please press \'0\' key to exit program..\n')
isStart = raw_input('Please press a key that must be in above list..')
if isStart == 1:
parse.__is__process__ = False
elif isStart == 5:
parse.__is__process__ = True
elif isStart == 0 :
exit_program()
else:
continue
except Exception as ex:
logging.info('log..') #this log will write other console..
最佳答案
你真的不需要两个 python 控制台来完成这个。
如果您使用的是 linux 或 mac,请打开 python 控制台和第二个终端。
然后在第二个终端输入这个命令:
tail -f path_to/filename_of_logfile
这将自动刷新日志文件。
如果您绝对不能使用文件,另一种解决方案是使用套接字来与 python 程序进行通信。这是一个帮助您入门的链接:
关于python - 在 python 中使用多个控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17405682/