Blame SOURCES/00257-threading-condition-wait.patch

43e83c
diff --git a/Lib/threading.py b/Lib/threading.py
43e83c
index 7ab9ad8..dcedd3b 100644
43e83c
--- a/Lib/threading.py
43e83c
+++ b/Lib/threading.py
43e83c
@@ -3,7 +3,7 @@
43e83c
 import sys as _sys
43e83c
 import _thread
43e83c
 
43e83c
-from time import monotonic as _time
43e83c
+from time import monotonic as _time, sleep as _sleep
43e83c
 from traceback import format_exc as _format_exc
43e83c
 from _weakrefset import WeakSet
43e83c
 from itertools import islice as _islice, count as _count
43e83c
@@ -296,7 +296,25 @@ class Condition:
43e83c
                 gotit = True
43e83c
             else:
43e83c
                 if timeout > 0:
43e83c
-                    gotit = waiter.acquire(True, timeout)
43e83c
+                    # rhbz#2003758: Avoid waiter.acquire(True, timeout) since
43e83c
+                    # it uses the system clock internally.
43e83c
+                    #
43e83c
+                    # Balancing act:  We can't afford a pure busy loop, so we
43e83c
+                    # have to sleep; but if we sleep the whole timeout time,
43e83c
+                    # we'll be unresponsive.  The scheme here sleeps very
43e83c
+                    # little at first, longer as time goes on, but never longer
43e83c
+                    # than 20 times per second (or the timeout time remaining).
43e83c
+                    endtime = _time() + timeout
43e83c
+                    delay = 0.0005 # 500 us -> initial delay of 1 ms
43e83c
+                    while True:
43e83c
+                        gotit = waiter.acquire(0)
43e83c
+                        if gotit:
43e83c
+                            break
43e83c
+                        remaining = min(endtime - _time(), timeout)
43e83c
+                        if remaining <= 0:
43e83c
+                            break
43e83c
+                        delay = min(delay * 2, remaining, .05)
43e83c
+                        _sleep(delay)
43e83c
                 else:
43e83c
                     gotit = waiter.acquire(False)
43e83c
             return gotit