Search code examples
pythongevent

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


I have a Python unittest that depends on multiprocessing and therefore must not run when Gevent's monkey-patching is active. Is there a Python statement that can tell me whether gevent.monkey.patch_all has run or not?


Solution

  • 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
    gevent.monkey.patch_all()
    import socket
    
    if socket.socket is gevent.socket.socket:
        print "gevent monkey patch has occurred"