multiprocessing-logging
When using the multiprocessing
module, logging becomes less useful since
sub-processes should log to individual files/streams or there's the risk of
records becoming garbled.
This simple module implements a Handler
that when set on the root
Logger
will handle tunneling the records to the main process so that
they are handled correctly.
Unfortunately, this technique only works with Processes and not with a Pool of processes. If you need this, I'd welcome a pull request! :)
It's currently tested in Linux and Python 2.7 and 3.4.
Origin
This library was taken verbatim from a StackOverflow post and extracted into a module so that I wouldn't have to copy the code in every project.
Usage
Before you start logging but after you configure the logging framework (maybe with logging.basicConfig(...)
), do the following:
import multiprocessing_logging
multiprocessing_logging.install_mp_handler()
and that's it.