[issue24717] python logging handler not used when added after a process is started

Vinay Sajip report at bugs.python.org
Mon Jul 27 14:22:42 CEST 2015


Vinay Sajip added the comment:

Context is crucial. The Python documentation is not wrong, but doesn't belabour the point that it refers to the most common, single-process case. The problem you encountered is not specific to logging: you need to understand all aspects of how forking works and how Python works within the framework of POSIX and forking. It's a non-trivial topic and too much to go into here - suffice to say that in order to get the result you expect, you need (as I said in an earlier comment) to configure logging in code that is called in each process of a multiple-process setup. If you add two handlers to a logger, one before forking and one after forking, then the child process might behave as expected, but logging from the parent process could output multiple copies of the same message. If you don't do any logging in the parent, that might be OK, but it still doesn't feel like the right approach.

You might find it helpful to read my 2010 blog post about logging and multiprocessing:

http://plumberjack.blogspot.co.uk/2010/09/using-logging-with-multiprocessing.html

AFAIK nothing fundamental has changed since then to invalidate the overall thrust of that post.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24717>
_______________________________________


More information about the Python-bugs-list mailing list