A. Jesse Jiryu Davis A. Jesse Jiryu Davis - 11 months ago 61
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"