title: Python multithread using queue - the program gets blocked forever
body: <p>I am not sure which part of my program is wrong. It will be blocked at the join() calls of two queues. However, if I removed the 2 join calls, the program does not work at all. </p>
  
  <pre><code>    import threading
      import Queue
  
      queue = Queue.Queue()
      out_queue = Queue.Queue()
  
      fruits = ['apple', 'strawberry', 'banana', 'peach', 'rockmelon']
  
      class WorkerThread(threading.Thread):
          def __init__(self, queue, out_queue):
              threading.Thread.__init__(self)
              self.queue = queue
              self.out_queue = out_queue
          def run(self):
              print 'run'
              while not self.queue.empty():
                  name = self.queue.get()
                  self.out_queue.put(name)
                  self.queue.task_done()
  
      def main():
          print 'start'
          for i in xrange(5):
              t = WorkerThread(queue, out_queue)
              t.setDaemon(True)
              t.start()
          #populate the queue
          for fruit in fruits:
              queue.put(fruit)
          queue.join()
          out_queue.join()
          while not out_queue.empty():
              print out_queue.get()
          print 'end'
  
      if __name__=='__main__':
          main()
  </code></pre>
  
  <p>Thanks in advance. </p>