From 0f362f697ce3c5a2449e6bece5d24e07c90232d7 Mon Sep 17 00:00:00 2001 From: catborise Date: Fri, 2 Oct 2026 12:04:41 +0300 Subject: [PATCH] fix(wsgi): only install SIGCHLD handler from the main thread runserver imports the WSGI application from a worker thread, where signal.signal() raises ValueError and the dev server fails to start. Gunicorn imports it from the worker's main thread, so production keeps reaping child processes as before. --- webvirtcloud/wsgi.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/webvirtcloud/wsgi.py b/webvirtcloud/wsgi.py index e6647f0b..79961a9a 100644 --- a/webvirtcloud/wsgi.py +++ b/webvirtcloud/wsgi.py @@ -8,7 +8,12 @@ https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ """ import signal -signal.signal(signal.SIGCHLD, signal.SIG_IGN) +import threading + +# Reap child processes to avoid zombies. Signal handlers can only be set from +# the main thread; runserver imports this module from a worker thread. +if threading.current_thread() is threading.main_thread(): + signal.signal(signal.SIGCHLD, signal.SIG_IGN) import os