python - Gevent queue high CPU usage -


why code permanently uses 95% of cpu? producer doesn't sending request, cpu hot. how lower cpu usage without adding explicit non-zero sleep timeout in consumer greenlet?

from gevent import queue gevent import sleep gevent import greenlet  def cons(q):     while true:         try:             data = q.get_nowait()         except queue.empty:             sleep(0)             continue         print data  def prod(q):     while true:         #q.put_nowait('hello')         sleep(1)   if __name__ == '__main__':      q = queue.queue()     cons1 = greenlet.spawn(cons, q)     prod1 = greenlet.spawn(prod, q)     cons1.join()     prod1.join() 

in line 8, use get() instead of get_nowait()

data = q.get() 

super simple, consumer block while waiting more work.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -