]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-126016: Fix flaky test by allowing the SIGINT return code (GH-139219)
authorPeter Bierma <zintensitydev@gmail.com>
Tue, 23 Sep 2025 14:09:19 +0000 (10:09 -0400)
committerGitHub <noreply@github.com>
Tue, 23 Sep 2025 14:09:19 +0000 (16:09 +0200)
Lib/test/test_interpreters/test_api.py

index 8e9f1c3204a8bbe7497decf25e426c312fdd1aa8..9a5ee03e4722c0753a608d0e56cfca5cb8358a8e 100644 (file)
@@ -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):