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)