Do logging handlers use separate threads?

99封情书 提交于 2019-12-10 15:56:44

问题


Python's logging handlers are great. Some of them, such as the SMTPHandler may take a long while to execute (contacting an SMTP server and all). Are they executed on a separate thread as to not block the main program?


回答1:


SMTPHandler uses smtplib and when sending an email with this library, your process is blocked until it have been correctly sent, no thread created.

If you do not want to block your process when sending an email, you'll have to implement your own SMTPHandler and override the emit(self, record) method.

The less blocking handler is the SysLogHandler, because it is in general a local communication, and in UDP so the system doesn't wait for any acknowledgement from the destination.




回答2:


No, you should spawn a separate process, as far as I know.



来源:https://stackoverflow.com/questions/8590928/do-logging-handlers-use-separate-threads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!