Skip to content

Commit 6b4e3fe

Browse files
gh-126016: Fix flaky test by allowing the SIGINT return code (GH-139219)
1 parent dd683f8 commit 6b4e3fe

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Lib/test/test_interpreters/test_api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,12 @@ def test():
459459
error = proc.stderr.read()
460460
self.assertIn(b"KeyboardInterrupt", error)
461461
retcode = proc.wait()
462-
self.assertEqual(retcode, 0)
462+
# Sometimes we send the SIGINT after the subthread yields the GIL to
463+
# the main thread, which results in the main thread getting the
464+
# KeyboardInterrupt before finalization is reached. There's not
465+
# any great way to protect against that, so we just allow a -2
466+
# return code as well.
467+
self.assertIn(retcode, (0, -signal.SIGINT))
463468

464469

465470
class TestInterpreterIsRunning(TestBase):

0 commit comments

Comments
 (0)