[3.13] gh-154167: Fix test suite hang when SIGINT is ignored (GH-154168) (GH-154267)

serhiy-storchaka <[email protected]>
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/4479b8b438605882205a93864b9c7d8b51b6d876
commit: 4479b8b438605882205a93864b9c7d8b51b6d876
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-07-20T14:34:42Z
summary:

[3.13] gh-154167: Fix test suite hang when SIGINT is ignored (GH-154168) (GH-154267)

(cherry picked from commit 1047cbb9746f959f6787f2c393bd79cbae6100c5)

Co-authored-by: Serhiy Storchaka <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>

files:
A Misc/NEWS.d/next/Tests/2026-07-19-20-15-00.gh-issue-154167.sigint.rst
M Lib/test/libregrtest/setup.py

diff --git a/Lib/test/libregrtest/setup.py b/Lib/test/libregrtest/setup.py
index d50b2155a6bf047..49a4edeea2b9ef7 100644
--- a/Lib/test/libregrtest/setup.py
+++ b/Lib/test/libregrtest/setup.py
@@ -52,6 +52,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
index 000000000000000..b2620f4a0bee54c
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2026-07-19-20-15-00.gh-issue-154167.sigint.rst
@@ -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.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.