[pypy-commit] pypy default: Issue #2768

arigo pypy.commits at gmail.com
Thu Apr 12 03:40:11 EDT 2018


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r94309:0cb72dae7486
Date: 2018-04-12 09:39 +0200
http://bitbucket.org/pypy/pypy/changeset/0cb72dae7486/

Log:	Issue #2768

	Fall back to not using _py3k_acquire(), in case eventlet patches
	various classes

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
@@ -351,6 +351,21 @@
                         # forward-compatibility reasons we do the same.
                         waiter.acquire()
                         gotit = True
+                    except AttributeError:
+                        # someone patched the 'waiter' class, probably.
+                        # Fall back to the standard CPython logic.
+                        # See the CPython lib for the comments about it...
+                        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)
                 else:
                     gotit = waiter.acquire(False)
                 if not gotit:


More information about the pypy-commit mailing list