Do logging handlers use separate threads?

2019-06-26 11:16发布

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?

2条回答
来,给爷笑一个
2楼-- · 2019-06-26 11:55

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

查看更多
Deceive 欺骗
3楼-- · 2019-06-26 12:11

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.

查看更多
登录 后发表回答