title: Gevent threads don't finish even though all the Queue items are exhausted
body: <p>I'm trying to set up a simple producer-consumer system in Gevent but my script doesn't exit:</p>
  
  <pre><code>import gevent
  from gevent.queue import *
  import time
  import random
  
  q = Queue()
  workers = []
  
  def do_work(wid, value):
      """
      Actual blocking function
      """
      gevent.sleep(random.randint(0,2))
      print 'Task', value, 'done', wid
      return
  
  
  def worker(wid):
      """
      Consumer
      """
      while True:
          item = q.get()
          do_work(wid, item)
  
  
  def producer():
      """
      Producer
      """
      for i in range(4):
          workers.append(gevent.spawn(worker, random.randint(1, 100000)))
  
  
      for item in range(1, 9):
           q.put(item)
  
  producer()
  gevent.joinall(workers)
  </code></pre>
  
  <p>I haven't been able to find good examples/tutorials on using Gevent so what I've pasted above is what I've cobbled up from the internet.</p>
  
  <p>Multiple workers get activated, the items go into the queue but even when everything in the queue finishes, the main program doesn't exit. I have to press <code>CTRL ^ C</code>.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Thanks.</p>
  
  <p>On a side note: if there is anything my script that could be improved, please let me know. Simple things like checking when the Queue is empty, etc.</p>