From 2820bf7ad3fc4e78493d856ba49bf0cd7f92563e Mon Sep 17 00:00:00 2001 From: Christian Aurich Zanettini Martins Date: Tue, 6 Oct 2026 12:12:15 -0300 Subject: [PATCH] gh-74112: Fix race in test_interrupt_blocking_call (GH-158914) On a loaded machine the KeyboardInterrupt could be raised before the main thread reached time.sleep(), escape the test and stop the whole regrtest run. (cherry picked from commit ea0ee925ad755999d6095ba61de2652ec9275f04) Co-authored-by: Christian Aurich Zanettini Martins --- Lib/idlelib/idle_test/test_run.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/idlelib/idle_test/test_run.py b/Lib/idlelib/idle_test/test_run.py index bc762648c80785d..9f385ec43f60a26 100644 --- a/Lib/idlelib/idle_test/test_run.py +++ b/Lib/idlelib/idle_test/test_run.py @@ -546,9 +546,11 @@ def test_interrupt_blocking_call(self): # gh-74112: interrupt the main thread blocked in time.sleep(). timer = threading.Timer(0.1, self.ex.interrupt_the_server) self.addCleanup(timer.join) - timer.start() start = time.monotonic() with self.assertRaises(KeyboardInterrupt): + # On a loaded machine the signal can arrive before the main + # thread reaches time.sleep(), so start the timer in the block. + timer.start() time.sleep(support.SHORT_TIMEOUT) self.assertLess(time.monotonic() - start, support.SHORT_TIMEOUT / 2)