title: Preferred way to empty multiprocessing.queue(-1) in python
body: <p>I want to pull all the items currently in a queue. There is another thread constantly putting items in the other end, and every period I want to get all the items currently in the queue.</p>
  
  <p>Is there some reason to prefer:</p>
  
  <pre><code>res = []
  while q.qsize &gt; 0 :
      res.append(q.get())
  </code></pre>
  
  <p>or</p>
  
  <pre><code>res = []
  while True :
      try :
           res.append(q.get(block=False)) 
      except Queue.Empty :
           break
  </code></pre>
  
  <p>Now the docs specifically say that the qsize() > 0 will not prevent the queue from blocking on a get, but is this true only in the case where multiple threads can take from the output?</p>
  
  <blockquote>
    <p>Queue.<strong>qsize()</strong> Return the approximate size of the queue. Note, qsize() > 0 doesn’t guarantee that a subsequent get() will not block, nor will qsize() &lt; maxsize guarantee that put() will not block.</p>
  </blockquote>
  
  <p>Does this mean that the second form should always be preferred? EAFP and all that? Also, is there any cost to calling q.qsize()? Does it block the other end of the queue in order to count?</p>
  
  <p>I guess I have talked myself into using the second form but it seems much less clean to me.</p>