Commit 704d99f0 authored by Kirill Smelkov's avatar Kirill Smelkov

gpython: Workaround PyPy2 vs Gevent patch_thread crash

	pypy-gevent runtests: commands[0] | gpython -m pytest gpython/ golang/
	Traceback (most recent call last):
	  File "/home/kirr/src/tools/go/pygolang/.tox/pypy-gevent/bin/gpython", line 10, in <module>
	    sys.exit(main())
	  File "/home/kirr/src/tools/go/pygolang/.tox/pypy-gevent/site-packages/gpython/__init__.py", line 153, in main
	    _ = monkey.patch_all()      # XXX sys=True ?
	  File "/home/kirr/src/tools/go/pygolang/.tox/pypy-gevent/site-packages/gevent/monkey.py", line 976, in patch_all
	    patch_thread(Event=Event, _warnings=_warnings)
	  File "/home/kirr/src/tools/go/pygolang/.tox/pypy-gevent/site-packages/gevent/monkey.py", line 178, in ignores
	    return func(*args, **kwargs)
	  File "/home/kirr/src/tools/go/pygolang/.tox/pypy-gevent/site-packages/gevent/monkey.py", line 588, in patch_thread
	    _patch_existing_locks(threading_mod)
	  File "/home/kirr/src/tools/go/pygolang/.tox/pypy-gevent/site-packages/gevent/monkey.py", line 492, in _patch_existing_locks
	    if o._RLock__owner is not None:
	AttributeError: 'thread.RLock' object has no attribute '_RLock__owner'

It will be fixed on next Gevent release, however until then the crash is there
and we have to workaround: we can skip patching existing locks as it will be
the same behaviour of next Gevent release, since its just not possible to patch
locks created via instantiated C-level classes:

https://github.com/gevent/gevent/commit/d0e04658

We are doing monkey-patching very early, so it should be safe.
parent 731f39e3
...@@ -136,7 +136,8 @@ def main(): ...@@ -136,7 +136,8 @@ def main():
avoid = ['pkg_resources', 'golang', 'socket', 'select', 'threading', avoid = ['pkg_resources', 'golang', 'socket', 'select', 'threading',
'thread', 'ssl', 'subprocess'] 'thread', 'ssl', 'subprocess']
# pypy7 made time always pre-imported (https://bitbucket.org/pypy/pypy/commits/6759b768) # pypy7 made time always pre-imported (https://bitbucket.org/pypy/pypy/commits/6759b768)
if 'PyPy' not in sys.version: pypy = ('PyPy' in sys.version)
if not pypy:
avoid.append('time') avoid.append('time')
bad = [] bad = []
for mod in avoid: for mod in avoid:
...@@ -150,7 +151,14 @@ def main(): ...@@ -150,7 +151,14 @@ def main():
# make gevent pre-available & stdlib patched # make gevent pre-available & stdlib patched
from gevent import monkey from gevent import monkey
_ = monkey.patch_all() # XXX sys=True ? # XXX workaround for gevent vs pypy2 crash.
# XXX remove when gevent-1.4.1 is relased (https://github.com/gevent/gevent/pull/1357).
patch_thread=True
if pypy and sys.version_info.major == 2:
_ = monkey.patch_thread(existing_locks=False)
assert _ in (True, None)
patch_thread=False
_ = monkey.patch_all(thread=patch_thread) # XXX sys=True ?
if _ not in (True, None): # patched or nothing to do if _ not in (True, None): # patched or nothing to do
# XXX provide details # XXX provide details
raise RuntimeError('gevent monkey-patching failed') raise RuntimeError('gevent monkey-patching failed')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment