title: explicit switch() with gevent
body: <p>I have a primitive producer/consumer script running in gevent. It starts a few producer functions that put things into a <code>gevent.queue.Queue</code>, and one consumer function that fetches them out of the queue again:</p>
  
  <pre><code>from __future__ import print_function
  
  import time
  
  import gevent
  import gevent.queue
  import gevent.monkey
  
  q = gevent.queue.Queue()
  
  # define and spawn a consumer
  def consumer():
      while True:
          item = q.get(block=True)
          print('consumer got {}'.format(item))
  
  consumer_greenlet = gevent.spawn(consumer)
  
  # define and spawn a few producers
  def producer(ID):
      while True:
          print("producer {} about to put".format(ID))
          q.put('something from {}'.format(ID))
          time.sleep(0.1)
  #       consumer_greenlet.switch()      
  
  producer_greenlets = [gevent.spawn(producer, i) for i in range(5)]
  
  # wait indefinitely
  gevent.monkey.patch_all()
  print("about to join")
  consumer_greenlet.join()
  </code></pre>
  
  <p>It works fine if I let gevent handle the scheduling implicitly (e.g. by calling time.sleep or some other <code>gevent.monkey.patch()</code>ed function), however when I switch to the consumer explicitly (replace <code>time.sleep</code>with the commented-out <code>switch</code> call), gevent raises an AssertionError:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/my/virtualenvs/venv/local/lib/python2.7/site-packages/gevent/greenlet.py", line 327, in run
      result = self._run(*self.args, **self.kwargs)
    File "switch_test.py", line 14, in consumer
      item = q.get(block=True)
    File "/my/virtualenvs/venv/lib/python2.7/site-packages/gevent/queue.py", line 201, in get
      assert result is waiter, 'Invalid switch into Queue.get: %r' % (result, )
  AssertionError: Invalid switch into Queue.get: ()
  &lt;Greenlet at 0x7fde6fa6c870: consumer&gt; failed with AssertionError
  </code></pre>
  
  <p>I would like to employ explicit switching because in production I have a lot of producers, gevent's scheduling does not allocate nearly enough runtime to the consumer and the queue gets longer and longer (which is bad). Alternatively, any insights into how to configure or modify gevent's scheduler is greatly appreciated.</p>
  
  <p>This is on Python 2.7.2, gevent 1.0.1 and greenlet 0.4.5.</p>