title: Basic python multi-threading issue
body: <p>New to python and trying to understand multi-threading. Here's an example from python documentation on <a href="http://docs.python.org/library/queue.html#module-Queue" rel="nofollow">Queue</a></p>
  
  <p>For the heck of my life, I don't understand how this example is working. In the worker() function, there's an infinite loop. How does the worker know when to get out of the loop? There seems to be no breaking condition.</p>
  
  <p>And what exactly is the join doing at the end? Shouldn't I be joining the threads instead?</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>Also another question, When should multithreading be used and when should multiprocessing be used? </p>