]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-154167: Fix test suite hang when SIGINT is ignored (GH-154168)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 20 Jul 2026 14:14:50 +0000 (17:14 +0300)
committerGitHub <noreply@github.com>
Mon, 20 Jul 2026 14:14:50 +0000 (17:14 +0300)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Lib/test/libregrtest/setup.py
Misc/NEWS.d/next/Tests/2026-07-19-20-15-00.gh-issue-154167.sigint.rst [new file with mode: 0644]

index b9b76a44e3b4e798189d2efb993a5a8f1187b71e..d62194acd9c29e5aba27890ae76d3cbd94e0e7c8 100644 (file)
@@ -50,6 +50,14 @@ def setup_process() -> None:
         for signum in signals:
             faulthandler.register(signum, chain=True, file=stderr_fd)
 
+    # Restore the default SIGINT handler if there is no Python-level
+    # handler.  Python inherits the SIG_IGN disposition when the test
+    # suite runs as a shell background job; then asyncio.Runner does not
+    # install its own handler and _thread.interrupt_main() is a no-op,
+    # which makes some tests in test_asyncio and test_threading hang.
+    if signal.getsignal(signal.SIGINT) in (signal.SIG_IGN, signal.SIG_DFL):
+        signal.signal(signal.SIGINT, signal.default_int_handler)
+
     adjust_rlimit_nofile()
 
     support.record_original_stdout(sys.stdout)
diff --git a/Misc/NEWS.d/next/Tests/2026-07-19-20-15-00.gh-issue-154167.sigint.rst b/Misc/NEWS.d/next/Tests/2026-07-19-20-15-00.gh-issue-154167.sigint.rst
new file mode 100644 (file)
index 0000000..b2620f4
--- /dev/null
@@ -0,0 +1,3 @@
+The test runner (regrtest) now restores the default SIGINT handler if it
+was inherited as ignored, so the test suite no longer hangs when run as
+a shell background job.