Note that there are some explanatory texts on larger screens.

plurals
  1. POPython multiprocessing logging - why multiprocessing.get_logger
    primarykey
    data
    text
    <p>I've been struggled with multiprocessing logging for some time, and for many reasons.</p> <p>One of my reason is, why another get_logger.</p> <p>Of course I've seen <a href="https://stackoverflow.com/questions/641420/how-should-i-log-while-using-multiprocessing-in-python">this question</a> and it seems the logger that multiprocessing.get_logger returns do some "process-shared locks" magic to make logging handling smooth.</p> <p>So, today I looked into the multiprocessing code of Python 2.7 (/multiprocessing/util.py), and found that this logger is just a plain logging.Logger, and there's barely any magic around it.</p> <p>Here's the description in Python documentation, right before the get_logger function:</p> <blockquote> <p>Some support for logging is available. Note, however, that the logging package does not use process shared locks so it is possible (depending on the handler type) for messages from different processes to get mixed up.</p> </blockquote> <p>So when you use a wrong logging handler, even the get_logger logger may go wrong? I've used a program uses get_logger for logging for some time. It prints logs to StreamHandler and (seems) never gets mixed up.</p> <p>Now My theory is:</p> <ol> <li>multiprocessing.get_logger don't do process-shared locks at all</li> <li>StreamHandler works for multiprocessing, but FileHandler doesn't</li> <li>major purpose of this get_logger logger is for tracking processes' life-cycle, and provide a easy-to-get and ready-to-use logger that already logs process's name/id kinds of stuff</li> </ol> <p>Here's the question:</p> <p>Is my theory right?</p> <p>How/Why/When do you use this get_logger?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload