Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python日志记录在来自不同线程时不显示sys.stdout_Python_Multithreading_Logging_Telegram Bot - Fatal编程技术网

python日志记录在来自不同线程时不显示sys.stdout

python日志记录在来自不同线程时不显示sys.stdout,python,multithreading,logging,telegram-bot,Python,Multithreading,Logging,Telegram Bot,我现在在登录我的多线程python应用程序时遇到了一个奇怪的问题。每当调试应用程序时,我都会在标准输出中正确地看到日志输出,例如 2016-11-05 21:51:36,851 (connectionpool.py:735 MainThread) INFO - requests.packages.urllib3.connectionpool: "Starting new HTTPS connection (1): api.telegram.org" 2016-11-05 21:51:41

我现在在登录我的多线程python应用程序时遇到了一个奇怪的问题。每当调试应用程序时,我都会在标准输出中正确地看到日志输出,例如

2016-11-05 21:51:36,851 (connectionpool.py:735 MainThread) INFO -     requests.packages.urllib3.connectionpool: "Starting new HTTPS connection (1): api.telegram.org"
2016-11-05 21:51:41,920 (converter.py:16 WorkerThread1) DEBUG - converter: "resizing file test/test_input/"
2016-11-05 21:51:50,199 (bot.py:221 WorkerThread1) ERROR - __main__: "MoviePy error: failed to read the duration of file test/test_input/. 
但是,当我在没有调试的情况下运行代码时,来自
工作线程read1
的所有日志都会消失,只剩下
主线程的日志。代码保持不变,错误仍然存在。我想这与多线程有关。
WorkerThread1
是从
PyDatamebotAPI
框架启动的。我将日志输出到
sys.stdout

formatter = logging.Formatter(
    '%(asctime)s (%(filename)s:%(lineno)d %(threadName)s) %(levelname)s - %(name)s: "%(message)s"')
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setFormatter(formatter)
root = logging.getLogger()
root.setLevel(logging.NOTSET)
root.addHandler(stream_handler)
有什么想法吗


更新:它100%与多线程有关,因为当我告诉框架只使用一个线程时,会出现日志消息
pyTelegramBotAPI
使用
WorkerThread
ThreadPool
实现并发,如示例所示

您必须显示更多代码。在您显示的代码中,创建了
stream\u handler
,但在
addHandler
中使用了
handler


我猜您的日志记录级别设置不正确,导致来自
WorkingRead1
的所有日志未被记录。

您必须显示更多代码。在您显示的代码中,创建了
stream\u handler
,但在
addHandler
中使用了
handler


我猜您的日志记录级别设置不正确,导致来自
工作区read1的所有日志未被记录。

对不起,我已更正了代码<实际上使用了代码>流处理程序
。请参阅updatesorry,我已经更正了代码<实际上使用了代码>流处理程序
。请参阅updateUpdate:它100%与多线程有关,因为当我告诉框架仅使用一个线程时,日志消息会出现更新:它100%与多线程有关,因为当我告诉框架仅使用一个线程时,日志消息会出现