[BangPypers] real use case of gevent context switch gevent.sleep(0)

Noufal Ibrahim KV noufal at nibrahim.net.in
Sun Jun 21 09:31:04 CEST 2015

On Sun, Jun 21 2015, anu sree wrote:


> This code has two pause (gevent.sleep(0)), in Consumer.start and
> Worker.run.  Here control goes to Worker.run when Consumer.start
> pauses and Consumer.start gets control back when Worker.run
> pauses. There may be benefit from this switching, but I am still not
> understanding it.


The idea is that any non blocking call is an opportunity to switch
between greenlets. The monkey patching system will enable this.

If you don't have any place in your greenlets that are monkey patched
(and therefore allow switching), you can be a good citizen and drop in a
patched sleep call so that other greenlets will get time to
run. Otherwise, you'll simply hog the interpreter and no one else will
be able to run.

This the principle. I still don't understand your question.


More information about the BangPypers mailing list