Graphics Noob
Graphics Noob

Reputation: 10060

Does the python logging run in it's own thread?

I've found that logging I/O is a performance bottleneck of our program, so I'm thinkig of moving all logging I/O to a seperate thread. The problem is that I don't really know what's going on in the python logging module, and I'd hate to burn a day of work on something that the python logging module is already doing for me, or would be a waste of time for any other reasons. I've read the Python logging documentation and the only references to threads I've found are in reference to accessing the logger from different threads of a multithreaded application.

Does the python logging module create a seperate thread to handle I/O? If not, would it be worth my time to create a seperate thread to handle logging I/O?

Upvotes: 2

Views: 917

Answers (2)

carmiac
carmiac

Reputation: 359

As mata said, python logging does not run in its own thread. However, as as 3.2 it does provide tools to make it easy to have handlers that run in their own thread, QueueHandler and QueueListener. Take a look at the "Dealing with handlers that block" section of the logging cookbook at http://docs.python.org/3.3/howto/logging-cookbook.html#dealing-with-handlers-that-block

Upvotes: 0

mata
mata

Reputation: 69062

no, it doesn't. you can check it yourself in the sources.

you could probably write your own threaded Logger class using a Queue to queue new log records. But you should have a look at how the information about the current thread is generated in the LogRecord class.

Upvotes: 3

Related Questions