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

anu sree anusree.a04 at gmail.com
Sun Jun 21 16:18:41 CEST 2015

Thanks noufal,

I got it.

After gevent.spawn, we have to do join or gevent.joinall or gevent.sleep or
patched library call to start the greenlets, right ?

I have see the code which not using any of these after gevent.spawn, How it
is working there ?


On Sun, Jun 21, 2015 at 1:01 PM, Noufal Ibrahim KV <noufal at nibrahim.net.in>

> 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.
> --
> Cordially,
> Noufal
> http://nibrahim.net.in
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> https://mail.python.org/mailman/listinfo/bangpypers

More information about the BangPypers mailing list