Skip to content

Instantly share code, notes, and snippets.

@colesbury
Created April 30, 2024 15:40
Show Gist options
  • Save colesbury/74e2523c3622f479f7e39fc62c5dc948 to your computer and use it in GitHub Desktop.
Save colesbury/74e2523c3622f479f7e39fc62c5dc948 to your computer and use it in GitHub Desktop.
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 362a3f9c4a..39afc9efb0 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -2029,6 +2029,7 @@ def test_interrupt_main_subthread(self):
# Calling start_new_thread with a function that executes interrupt_main
# should raise KeyboardInterrupt upon completion.
def call_interrupt():
+ time.sleep(0.02) # give main a chance to reach t.join()
_thread.interrupt_main()
t = threading.Thread(target=call_interrupt)
with self.assertRaises(KeyboardInterrupt):
diff --git a/Lib/threading.py b/Lib/threading.py
index 31ab77c92b..89085d9ca9 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -5,7 +5,7 @@
import _thread
import warnings
-from time import monotonic as _time
+from time import monotonic as _time, sleep as _sleep
from _weakrefset import WeakSet
from itertools import count as _count
try:
@@ -365,6 +365,7 @@ def wait(self, timeout=None):
gotit = waiter.acquire(False)
return gotit
finally:
+ _sleep(0.1)
self._acquire_restore(saved_state)
if not gotit:
try:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment