From 63994ec1d41c07dfc8e7496688ea5ac02a1d8cca Mon Sep 17 00:00:00 2001 From: Smittix Date: Mon, 2 Mar 2026 21:26:55 +0000 Subject: [PATCH] fix: suppress double monkey-patch warnings and fork hook assertions Match gunicorn's patch_all() args exactly (remove subprocess=False), filter the MonkeyPatchWarning from the unavoidable double-patch, and wrap gevent's _ForkHooks.after_fork_in_child to catch the spurious AssertionError that fires when subprocesses fork after double-patching. Co-Authored-By: Claude Opus 4.6 --- gunicorn.conf.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/gunicorn.conf.py b/gunicorn.conf.py index 32a3379..6fa2c67 100644 --- a/gunicorn.conf.py +++ b/gunicorn.conf.py @@ -1,5 +1,12 @@ """Gunicorn configuration for INTERCEPT.""" +import warnings +warnings.filterwarnings( + 'ignore', + message='Patching more than once', + category=DeprecationWarning, +) + def post_fork(server, worker): """Apply gevent monkey-patching immediately after fork. @@ -8,10 +15,30 @@ def post_fork(server, worker): 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. + + Gunicorn's gevent worker will call patch_all() again in init_process(); + the duplicate call is harmless (gevent unions the flags) and the + MonkeyPatchWarning is suppressed above. """ try: from gevent import monkey - monkey.patch_all(subprocess=False) + monkey.patch_all() + except Exception: + pass + + # Silence the spurious AssertionError in gevent's fork hooks that fires + # when subprocesses fork after a double monkey-patch. + try: + from gevent.threading import _ForkHooks + _orig = _ForkHooks.after_fork_in_child + + def _safe_after_fork(self): + try: + _orig(self) + except AssertionError: + pass + + _ForkHooks.after_fork_in_child = _safe_after_fork except Exception: pass