From 6011d6fb413c72328a11094f676f6952780b52f4 Mon Sep 17 00:00:00 2001 From: Smittix Date: Mon, 2 Mar 2026 21:24:04 +0000 Subject: [PATCH] fix: apply gevent monkey-patch in post_fork to prevent ARM worker deadlock Gunicorn's gevent worker deadlocks during init_process() on Raspberry Pi (ARM) before it can apply its own monkey-patching. Patching in post_fork runs immediately after fork and before worker init, avoiding the race. Co-Authored-By: Claude Opus 4.6 --- gunicorn.conf.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gunicorn.conf.py b/gunicorn.conf.py index 81edf93..32a3379 100644 --- a/gunicorn.conf.py +++ b/gunicorn.conf.py @@ -1,6 +1,21 @@ """Gunicorn configuration for INTERCEPT.""" +def post_fork(server, worker): + """Apply gevent monkey-patching immediately after fork. + + Gunicorn's built-in gevent worker is supposed to handle this, but on + some platforms (notably Raspberry Pi / ARM) the worker deadlocks during + its own init_process() before it gets to patch. Doing it here — right + after fork, before any worker initialisation — avoids the race. + """ + try: + from gevent import monkey + monkey.patch_all(subprocess=False) + except Exception: + pass + + def post_worker_init(worker): """Suppress noisy SystemExit tracebacks during gevent worker shutdown.