diff options
author | Antonio Cuni <anto.cuni@gmail.com> | 2020-10-22 03:50:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-22 04:50:30 +0300 |
commit | 2f5052671d5365323dc5e0b1f2b5a20686741829 (patch) | |
tree | 018bb8ba5ebe1f02356ed48d87a6a91f7872126f | |
parent | e918595a8ffc241a851ff270a6279d6a9c1797b7 (diff) | |
download | eventlet-2f5052671d5365323dc5e0b1f2b5a20686741829.tar.gz |
don't crash on PyPy 7.0.0 https://github.com/eventlet/eventlet/pull/547
PyPy 7.0.0 uses 'py3-style' rlocks, i.e. they are implemented natively instead of being in pure-python.
Fixes the code in the sense that at least doesn't crash on PyPy, but it still suffers of https://github.com/eventlet/eventlet/issue/546 as python3.6 does.
-rw-r--r-- | eventlet/patcher.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/eventlet/patcher.py b/eventlet/patcher.py index 030fa54..2b4ab6c 100644 --- a/eventlet/patcher.py +++ b/eventlet/patcher.py @@ -379,18 +379,25 @@ def _green_existing_locks(): import eventlet.green.thread lock_type = type(threading.Lock()) rlock_type = type(threading.RLock()) - if sys.version_info[0] >= 3: + if hasattr(threading, '_PyRLock'): + # this happens on CPython3 and PyPy >= 7.0.0: "py3-style" rlocks, they + # are implemented natively in C and RPython respectively + py3_style = True pyrlock_type = type(threading._PyRLock()) + else: + # this happens on CPython2.7 and PyPy < 7.0.0: "py2-style" rlocks, + # they are implemented in pure-python + py3_style = False + pyrlock_type = None + # We're monkey-patching so there can't be any greenlets yet, ergo our thread # ID is the only valid owner possible. tid = eventlet.green.thread.get_ident() for obj in gc.get_objects(): if isinstance(obj, rlock_type): - if (sys.version_info[0] == 2 and - isinstance(obj._RLock__block, lock_type)): + if not py3_style and isinstance(obj._RLock__block, lock_type): _fix_py2_rlock(obj, tid) - elif (sys.version_info[0] >= 3 and - not isinstance(obj, pyrlock_type)): + elif py3_style and not isinstance(obj, pyrlock_type): _fix_py3_rlock(obj) |