Do log handlers use separate threads?

Python logging handlers are great. Some of them, such as SMTPHandler , may take a long time to complete (access to the SMTP server and all). Are they executed in a separate thread so as not to block the main program?

+4
source share
2 answers

SMTPHandler uses smtplib and when sending an email with this library, your process is blocked until it is sent correctly, not a single thread will be created.

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

A less blocking handler is SysLogHandler , since it is usually a local connection in UDP, so the system does not wait for confirmation from the destination.

+2
source

No, you have to create a separate process, as far as I know.

+1
source

Source: https://habr.com/ru/post/1387389/


All Articles