title: Dumping a multiprocessing.Queue into a list
body: <p>I wish to dump a <code>multiprocessing.Queue</code> into a list. For that task I've written the following function:</p>
  
  <pre><code>import Queue
  
  def dump_queue(queue):
      """
      Empties all pending items in a queue and returns them in a list.
      """
      result = []
  
      # START DEBUG CODE
      initial_size = queue.qsize()
      print("Queue has %s items initially." % initial_size)
      # END DEBUG CODE
  
      while True:
          try:
              thing = queue.get(block=False)
              result.append(thing)
          except Queue.Empty:
  
              # START DEBUG CODE
              current_size = queue.qsize()
              total_size = current_size + len(result)
              print("Dumping complete:")
              if current_size == initial_size:
                  print("No items were added to the queue.")
              else:
                  print("%s items were added to the queue." % \
                        (total_size - initial_size))
              print("Extracted %s items from the queue, queue has %s items \
              left" % (len(result), current_size))
              # END DEBUG CODE
  
              return result
  </code></pre>
  
  <p>But for some reason it doesn't work.</p>
  
  <p>Observe the following shell session:</p>
  
  <pre><code>&gt;&gt;&gt; import multiprocessing
  &gt;&gt;&gt; q = multiprocessing.Queue()
  &gt;&gt;&gt; for i in range(100):
  ...     q.put([range(200) for j in range(100)])
  ... 
  &gt;&gt;&gt; q.qsize()
  100
  &gt;&gt;&gt; l=dump_queue(q)
  Queue has 100 items initially.
  Dumping complete:
  0 items were added to the queue.
  Extracted 1 items from the queue, queue has 99 items left
  &gt;&gt;&gt; l=dump_queue(q)
  Queue has 99 items initially.
  Dumping complete:
  0 items were added to the queue.
  Extracted 3 items from the queue, queue has 96 items left
  &gt;&gt;&gt; l=dump_queue(q)
  Queue has 96 items initially.
  Dumping complete:
  0 items were added to the queue.
  Extracted 1 items from the queue, queue has 95 items left
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>What's happening here? Why aren't all the items being dumped?</p>