title: Python threads and queue example
body: <p>I'm new to python (I come from PHP), I've been reading tutorials and trying things for a couple of days but I can't understand this queue example (<a href="http://docs.python.org/2/library/queue.html">http://docs.python.org/2/library/queue.html</a>) </p>
  
  <pre><code>def worker():
      while True:
          item = q.get()
          do_work(item)
          q.task_done()
  
  q = Queue()
  for i in range(num_worker_threads):
       t = Thread(target=worker)
       t.daemon = True
       t.start()
  
  for item in source():
      q.put(item)
  
  q.join()       # block until all tasks are done
  </code></pre>
  
  <p>The thing I don't understand is how the worker thread completes and exists. I've read q.get() blocks until an item is available, so if all items are processed and none is left in the queue why q.get() doesn't block forever?</p>