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

Noufal Ibrahim noufal at nibrahim.net.in
Mon Jun 22 06:54:27 CEST 2015


On 2015-06-21 19:48, anu sree wrote:
> 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 ?

join (and joinall) will pause the current greenlet till the ones you've 
joined terminate (similar to the threading.Thread join method).

gevent.sleep will suspend the execution of the current greenlet and let 
other greenlets get some time to execute.

> I have see the code which not using any of these after gevent.spawn, 
> How it
> is working there ?
> https://github.com/Juniper/contrail-controller/blob/master/src/opserver/uveserver.py#L656

Neither of these are *necessary*. Just creating a greenlet and 
`.start`ing it will make it run similar to a thread as long as other 
greenlets don't hog the CPU and have some calls that can context switch.




More information about the BangPypers mailing list