title: Detect when multiprocessing queue is empty and closed
body: <p>Let's say I have two processes: a reader and a writer. How does the writer detect when the reader has finished writing values?</p>
  
  <p>The <code>multiprocessing</code> module has <a href="https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Queue.close" rel="noreferrer">a queue with a close method</a> that seems custom-built for this purpose. But how do you detect when the queue has been closed?</p>
  
  <p>This doesn't seem to work, as the writer never exits:</p>
  
  <pre><code>import multiprocessing as mp
  
  def getter(q):
      while True:
          try:
              print(q.get())
          except Exception:
              break
  
  def putter(q):
      q.put(1)
      q.put(2)
      q.close()
  
  q = mp.Queue()
  writer = mp.Process(target=putter, args=(q, ))
  reader = mp.Process(target=getter, args=(q, ))
  reader.start()
  writer.start()
  
  writer.join()
  reader.join()
  </code></pre>
  
  <p>Should the reader-writer pair use a sentinel value to signal end of writing? Then what's the point of having the <code>close</code> method?</p>
  
  <p>EDIT: While <a href="https://stackoverflow.com/questions/3605188/communicating-end-of-queue">this question</a> asks about the Queue module (now <a href="https://docs.python.org/3/library/queue.html" rel="noreferrer">queue</a>), I am asking specifically about <code>mp.Queue</code> and what the correct use of the <code>.close</code> method is.</p>