eventlet.greenthread.sleep VS time.sleep in monkey-patched environment

1.9k Views Asked by At

We're running a server on eventlet green-threads + monkey-patching everything. I need to implement wait loop with periodic check, and I want to put sleep inside.

Is there any difference between :

eventlet.greenthread.sleep(1) AND time.sleep(1) 

in monkey-patched environment? I'm wondering if monkey-patch handles time.sleep

1

There are 1 best solutions below

0
On BEST ANSWER

They're the same in a monkey-patched environment. eventlet monkey patches time.sleep by default:

No monkey patch:

>>> import time
>>> time.sleep.__module__
'time'

With monkey-patch:

>>> import eventlet
>>> eventlet.monkey_patch()
>>> import time
>>> time.sleep.__module__
'eventlet.greenthread'

The only way it wouldn't be monkey-patch is if the eventlet.monkey_patch call specifies a subset of modules to monkey-patch, leaving out 'time':

>>> import eventlet
>>> eventlet.monkey_patch(socket=True, thread=True)
>>> import time
>>> time.sleep.__module__
'time'