From 6b4e3fe9d42708ca6e8cfb7407c22647787a6b29 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Tue, 23 Sep 2025 10:09:19 -0400 Subject: [PATCH] gh-126016: Fix flaky test by allowing the SIGINT return code (GH-139219) --- Lib/test/test_interpreters/test_api.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_interpreters/test_api.py b/Lib/test/test_interpreters/test_api.py index 8e9f1c3204a8..9a5ee03e4722 100644 --- a/Lib/test/test_interpreters/test_api.py +++ b/Lib/test/test_interpreters/test_api.py @@ -459,7 +459,12 @@ class InterpreterObjectTests(TestBase): error = proc.stderr.read() self.assertIn(b"KeyboardInterrupt", error) retcode = proc.wait() - self.assertEqual(retcode, 0) + # Sometimes we send the SIGINT after the subthread yields the GIL to + # the main thread, which results in the main thread getting the + # KeyboardInterrupt before finalization is reached. There's not + # any great way to protect against that, so we just allow a -2 + # return code as well. + self.assertIn(retcode, (0, -signal.SIGINT)) class TestInterpreterIsRunning(TestBase): -- 2.47.3