title: Status of mixing multiprocessing and threading in Python
body: <p>What are best practices or work-arounds for using both multiprocessing and user threads in the same python application in Linux with respect to Issue 6721, Locks in python standard library should be sanitized on fork?</p>
  
  <p>Why do I need both?  I use child processes to do heavy computation that produce data structure results that are much too large to return through a queue -- rather they must be immediately stored to disk.  It seemed efficient to have each of these child processes monitored by a separate thread, so that when finished, the thread could handle the IO of reading the large (eg multi GB) data back into the process where the result was needed for further computation in combination with the results of other child processes.
  The children processes would intermittently hang, which I just (after much head pounding) found was 'caused' by using the logging module.  Others have documented the problem here:</p>
  
  <p><a href="https://twiki.cern.ch/twiki/bin/view/Main/PythonLoggingThreadingMultiprocessingIntermixedStudy" rel="noreferrer">https://twiki.cern.ch/twiki/bin/view/Main/PythonLoggingThreadingMultiprocessingIntermixedStudy</a></p>
  
  <p>which points to this apparently unsolved python issue: Locks in python standard library should be sanitized on fork;  <a href="http://bugs.python.org/issue6721" rel="noreferrer">http://bugs.python.org/issue6721</a></p>
  
  <p>Alarmed at the difficulty I had tracking this down, I answered:</p>
  
  <p><a href="https://stackoverflow.com/questions/6244401/are-there-any-reasons-not-to-mix-multiprocessing-and-threading-module-in-python">Are there any reasons not to mix Multiprocessing and Threading module in Python</a></p>
  
  <p>with the rather unhelpful suggestion to 'Be careful' and links to the above.</p>
  
  <p>But the lengthy discussion re: Issue 6721 suggests that it is a 'bug' to use both multiprocessing (or os.fork) and user threads in the same application.  With my limited understanding of the problem, I find too much disagreement in the discussion to conclude what are the work-arounds or strategies for using both multiprocessing and threading in the same application.  My immediate problem was solved by disabling logging, but I create a small handful of other (explicit) locks in both parent and child processes, and suspect I am setting myself up for further intermittent deadlocks.</p>
  
  <p>Can you give practical recommendations to avoid deadlocks while using locks and/or the logging module while using threading and multiprocessing in a python (2.7,3.2,3.3) application?</p>