[pypy-commit] pypy default: Copy the py3k logic in Condition.wait()

arigo noreply at buildbot.pypy.org
Sun Feb 23 09:59:53 CET 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r69282:8d88f18cc867
Date: 2014-02-23 09:59 +0100
http://bitbucket.org/pypy/pypy/changeset/8d88f18cc867/

Log:	Copy the py3k logic in Condition.wait()

diff --git a/lib-python/2.7/threading.py b/lib-python/2.7/threading.py
--- a/lib-python/2.7/threading.py
+++ b/lib-python/2.7/threading.py
@@ -244,22 +244,11 @@
                 if __debug__:
                     self._note("%s.wait(): got it", self)
             else:
-                # Balancing act:  We can't afford a pure busy loop, so we
-                # have to sleep; but if we sleep the whole timeout time,
-                # we'll be unresponsive.  The scheme here sleeps very
-                # little at first, longer as time goes on, but never longer
-                # than 20 times per second (or the timeout time remaining).
-                endtime = _time() + timeout
-                delay = 0.0005 # 500 us -> initial delay of 1 ms
-                while True:
-                    gotit = waiter.acquire(0)
-                    if gotit:
-                        break
-                    remaining = endtime - _time()
-                    if remaining <= 0:
-                        break
-                    delay = min(delay * 2, remaining, .05)
-                    _sleep(delay)
+                # PyPy patch: use _py3k_acquire()
+                if timeout > 0:
+                    gotit = waiter._py3k_acquire(True, timeout)
+                else:
+                    gotit = waiter.acquire(False)
                 if not gotit:
                     if __debug__:
                         self._note("%s.wait(%s): timed out", self, timeout)


More information about the pypy-commit mailing list