A. Jesse Jiryu Davis A. Jesse Jiryu Davis - 1 year ago 87
Python Question

How do I detect if Gevent's monkey-patching is active?

I have a Python unittest that depends on

and therefore must not run when Gevent's monkey-patching is active. Is there a Python statement that can tell me whether
has run or not?

Answer Source

I'm not sure there is an idiomatic way, but one simple way would be to check the socket.socket class:

import gevent.monkey, gevent.socket
import socket

if socket.socket is gevent.socket.socket:
    print "gevent monkey patch has occurred"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download