Skip to content

Commit

Permalink
don't crash on PyPy 7.0.0 #547
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
antocuni committed Oct 22, 2020
1 parent e918595 commit 2f50526
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions eventlet/patcher.py
Expand Up @@ -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)


Expand Down

0 comments on commit 2f50526

Please sign in to comment.