Search code examples
pythondjangoceleryeventlet

Does Celery Automatically Monkey Patch when running eventlet pool?


This is a cross-post from the mailing list, hoping to get more eyes on the question. (original post)

When using running celery worker -p eventlet, does Celery do automatic monkey-patching of my code?

The docs don't mention anything about having to do patching and the official example doesn't do any explicit patching as well (even the gevent example doesn't do any patching). The example hints at patching being done automatically, but there is no explicit/definite answer.


Solution

  • When you run celery worker the function execute_from_commandline calls celery.__init__.maybe_patch_concurrency which calls _patch_eventlet which does:

    def _patch_eventlet():
        import eventlet
        import eventlet.debug
    
        eventlet.monkey_patch()
        blockdetect = float(os.environ.get('EVENTLET_NOBLOCK', 0))
        if blockdetect:
            eventlet.debug.hub_blocking_detection(blockdetect, blockdetect)