Skip to content

Commit 1047cbb

Browse files
gh-154167: Fix test suite hang when SIGINT is ignored (GH-154168)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 542b982 commit 1047cbb

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

Lib/test/libregrtest/setup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ def setup_process() -> None:
5050
for signum in signals:
5151
faulthandler.register(signum, chain=True, file=stderr_fd)
5252

53+
# Restore the default SIGINT handler if there is no Python-level
54+
# handler. Python inherits the SIG_IGN disposition when the test
55+
# suite runs as a shell background job; then asyncio.Runner does not
56+
# install its own handler and _thread.interrupt_main() is a no-op,
57+
# which makes some tests in test_asyncio and test_threading hang.
58+
if signal.getsignal(signal.SIGINT) in (signal.SIG_IGN, signal.SIG_DFL):
59+
signal.signal(signal.SIGINT, signal.default_int_handler)
60+
5361
adjust_rlimit_nofile()
5462

5563
support.record_original_stdout(sys.stdout)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The test runner (regrtest) now restores the default SIGINT handler if it
2+
was inherited as ignored, so the test suite no longer hangs when run as
3+
a shell background job.

0 commit comments

Comments
 (0)