Jonathan Livni
Jonathan Livni

Reputation: 107172

Do logging handlers use separate threads?

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?

Upvotes: 5

Views: 667

Answers (2)

Cédric Julien
Cédric Julien

Reputation: 80811

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.

Upvotes: 2

emirc
emirc

Reputation: 2018

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

Upvotes: 0

Related Questions