title: How to make sure queue is empty before exiting main thread
body: <p>I have a program that has two threads, the main thread and one additional that works on handling jobs from a FIFO queue.
  Something like this:</p>
  
  <pre><code>import queue
  import threading
  
  q = queue.Queue()
  
  def _worker():
    while True:
        msg = q.get(block=True)
        print(msg)
        q.task_done()
  
  t = threading.Thread(target=_worker)
  #t.daemon = True
  t.start()
  
  q.put('asdf-1')
  q.put('asdf-2')
  q.put('asdf-4')
  q.put('asdf-4')
  </code></pre>
  
  <p>What I want to accomplish is basically to make sure the queue is emptied before the main thread exits.
  If I set <em>t.daemon</em> to be True the program will exit before the queue is emptied, however if it's set to False the program will never exit. Is there some way to make sure the thread running the <em>_worker()</em> method clears the queue on main thread exit?</p>