title: Deadlock with logging multiprocess/multithread python script
body: <p>I am facing the problem with collecting logs from the following script.
  Once I set up the <code>SLEEP_TIME</code> to too "small" value, the LoggingThread
  threads somehow block the logging module. The script freeze on logging request
  in the <code>action</code> function. If the <code>SLEEP_TIME</code> is about 0.1 the script collect
  all log messages as I expect.</p>
  
  <p>I tried to follow <a href="https://stackoverflow.com/a/894284/533618">this answer</a> but it does not solve my problem.</p>
  
  <pre><code>import multiprocessing
  import threading
  import logging
  import time
  
  SLEEP_TIME = 0.000001
  
  logger = logging.getLogger()
  
  ch = logging.StreamHandler()
  ch.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(funcName)s(): %(message)s'))
  ch.setLevel(logging.DEBUG)
  
  logger.setLevel(logging.DEBUG)
  logger.addHandler(ch)
  
  
  class LoggingThread(threading.Thread):
  
      def __init__(self):
          threading.Thread.__init__(self)
  
      def run(self):
          while True:
              logger.debug('LoggingThread: {}'.format(self))
              time.sleep(SLEEP_TIME)
  
  
  def action(i):
      logger.debug('action: {}'.format(i))
  
  
  def do_parallel_job():
  
      processes = multiprocessing.cpu_count()
      pool = multiprocessing.Pool(processes=processes)
      for i in range(20):
          pool.apply_async(action, args=(i,))
      pool.close()
      pool.join()
  
  
  
  if __name__ == '__main__':
  
      logger.debug('START')
  
      #
      # multithread part
      #
      for _ in range(10):
          lt = LoggingThread()
          lt.setDaemon(True)
          lt.start()
  
      #
      # multiprocess part
      #
      do_parallel_job()
  
      logger.debug('FINISH')
  </code></pre>
  
  <p>How to use logging module in multiprocess and multithread scripts?</p>