mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-07-18 00:55:50 +00:00
Revert "fix(wsgi): ensure gevent monkey-patching before Django import chain"
This commit is contained in:
parent
7da7ba97a9
commit
d487bb5671
4 changed files with 0 additions and 55 deletions
|
|
@ -1,39 +0,0 @@
|
|||
"""Tests for dispatcharr/wsgi.py gevent monkey-patching."""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
|
||||
class TestWSGIGeventPatching(unittest.TestCase):
|
||||
"""Verify that wsgi.py applies gevent monkey-patching before Django imports.
|
||||
|
||||
These tests run in subprocesses because monkey.patch_all() must execute
|
||||
before any other imports. By the time Django's test runner loads this
|
||||
file, ssl/socket are already imported, so calling patch_all() in-process
|
||||
would fail. A subprocess mirrors how uWSGI actually loads wsgi.py.
|
||||
"""
|
||||
|
||||
def test_socket_is_patched_after_wsgi_import(self):
|
||||
"""Loading wsgi.py first (as uWSGI does) should patch sockets."""
|
||||
result = subprocess.run(
|
||||
[
|
||||
sys.executable, "-c",
|
||||
"import dispatcharr.wsgi; "
|
||||
"from gevent import monkey; "
|
||||
"assert monkey.is_module_patched('socket'), "
|
||||
"'socket module was not patched by wsgi.py'; "
|
||||
"print('PASS')",
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
env={**os.environ, "DJANGO_SETTINGS_MODULE": "dispatcharr.settings"},
|
||||
timeout=60,
|
||||
cwd="/app",
|
||||
)
|
||||
self.assertEqual(
|
||||
result.returncode,
|
||||
0,
|
||||
f"monkey-patching check failed:\n{result.stderr}",
|
||||
)
|
||||
|
|
@ -1,21 +1,6 @@
|
|||
"""
|
||||
WSGI config for dispatcharr project.
|
||||
"""
|
||||
# When running under uWSGI with gevent, ensure monkey-patching is fully
|
||||
# applied before any other imports. Django's setup triggers the import of
|
||||
# dispatcharr/__init__.py → celery.py, which initialises the Celery broker
|
||||
# transport. If those imports happen before sockets are patched, Celery's
|
||||
# Redis connection pool holds unpatched sockets that silently fail under
|
||||
# gevent's cooperative scheduling. Calling patch_all() here—before the
|
||||
# Django import chain—guarantees every socket (including pooled broker
|
||||
# connections) is gevent-aware. The call is idempotent, so it's harmless
|
||||
# if uWSGI's gevent plugin has already patched.
|
||||
try:
|
||||
from gevent import monkey
|
||||
monkey.patch_all()
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
import os
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue