Skip to content

Commit 4ca1391

Browse files
sl0thentr0pyclaude
andcommitted
test(celery): arm faulthandler at fixture scope, not in run_beat
Previous attempt put faulthandler.dump_traceback_later inside run_beat, but the py3.7 CI hang turns out to happen earlier — start_worker() never returns, so run_beat is never reached and the dump is never armed. Move the diagnostic into an autouse fixture in tests/integrations/celery/integration_tests/conftest.py so it covers the entire test body. Next CI hang should land a thread dump in the log showing where start_worker is wedged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 51a9076 commit 4ca1391

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

tests/integrations/celery/integration_tests/__init__.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import faulthandler
21
import os
32
import signal
43
import sys
@@ -66,12 +65,6 @@ def run_beat(celery_app, runtime_seconds=1, loglevel="warning", quiet=True):
6665
Run Celery Beat that immediately starts tasks.
6766
The Celery Beat instance is automatically terminated after `runtime_seconds`.
6867
"""
69-
# If anything below wedges this (forked) child process, dump all of its
70-
# thread stacks to stderr and exit, so a future hang surfaces a diagnosis
71-
# in the CI log instead of just stalling pytest-forked's waitpid in the
72-
# parent. Generous budget: kill_beat itself can wait up to ~30s for the
73-
# pidfile, plus runtime_seconds, plus celery beat shutdown.
74-
faulthandler.dump_traceback_later(45, exit=True)
7568
logger.info("Starting Celery Beat...")
7669
pid_file = os.path.join(tempfile.mkdtemp(), f"celery-beat-{os.getpid()}.pid")
7770

@@ -87,7 +80,4 @@ def run_beat(celery_app, runtime_seconds=1, loglevel="warning", quiet=True):
8780
quiet=quiet,
8881
pidfile=pid_file,
8982
)
90-
try:
91-
beat_instance.run()
92-
finally:
93-
faulthandler.cancel_dump_traceback_later()
83+
beat_instance.run()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import faulthandler
2+
3+
import pytest
4+
5+
6+
@pytest.fixture(autouse=True)
7+
def _dump_child_stacks_on_hang():
8+
"""
9+
Arm faulthandler inside the (pytest-forked) child process so that if a
10+
test wedges, the child dumps all of its thread stacks to stderr and exits
11+
instead of stalling pytest-forked's waitpid in the parent. Cancels on
12+
successful teardown so passing tests behave normally.
13+
"""
14+
faulthandler.dump_traceback_later(45, exit=True)
15+
yield
16+
faulthandler.cancel_dump_traceback_later()

0 commit comments

Comments
 (0)