gevent.time – Makes sleep gevent aware#

This module has all the members of time, but the sleep function is gevent.sleep().

The standard library time module, but sleep() is gevent-aware.

New in version 1.3a2.

sleep(seconds=0, ref=True)[source]#

Put the current greenlet to sleep for at least seconds.

seconds may be specified as an integer, or a float if fractional seconds are desired.

Tip

In the current implementation, a value of 0 (the default) means to yield execution to any other runnable greenlets, but this greenlet may be scheduled again before the event loop cycles (in an extreme case, a greenlet that repeatedly sleeps with 0 can prevent greenlets that are ready to do I/O from being scheduled for some (small) period of time); a value greater than 0, on the other hand, will delay running this greenlet until the next iteration of the loop.

If ref is False, the greenlet running sleep() will not prevent gevent.wait() from exiting.

Changed in version 1.3a1: Sleeping with a value of 0 will now be bounded to approximately block the loop for no longer than gevent.getswitchinterval().

See also

idle()