gevent-on-pypy / pypycore

gevent.core implemented as cffi module, might be used with pypy
56 stars 16 forks source link

Workaround for SSL exception with gevent on PyPy 2.2+ #11

Open parasyte opened 10 years ago

parasyte commented 10 years ago

gevent 1.0 on PyPy 2.2+ throws an exception when an SSL socket is created. Here's a partial stack trace (removing private paths, etc.)

Traceback (most recent call last):
  File "app_main.py", line 72, in run_toplevel

  *snip*

  File "/usr/local/Cellar/pypy/2.2.1/libexec/lib-python/2.7/httplib.py", line 1028, in getresponse
    response = self.response_class(*args, **kwds)
  File "/usr/local/Cellar/pypy/2.2.1/libexec/lib-python/2.7/httplib.py", line 346, in __init__
    self.fp = sock.makefile('rb', 0)
  File "*snip*/pypy-2.2.1/site-packages/gevent/ssl.py", line 364, in makefile
    return _fileobject(self, mode, bufsize, close=True)
  File "/usr/local/Cellar/pypy/2.2.1/libexec/lib-python/2.7/socket.py", line 300, in __init__
    sock._reuse()
AttributeError: 'SSLSocket' object has no attribute '_reuse'
Exception KeyError: KeyError(4372283104L,) in threading._shutdown() ignored

The workaround is taken directly from PyPy and applied to gevent. (Not optimal; this is a PyPy bug.)

https://github.com/pubnub/gevent/commit/bdee26cf71fb28644e7837942db09d3b0981af5c

parasyte commented 10 years ago

It just occurred that the same patch is needed on gevent's plain socket implementation.

https://github.com/pubnub/gevent/commit/e959acf2834e18bc3b41e0dcda583a428972f092

This branch can be used with PyPy 2.2+ and pypycore by following the pypycore README. Just replace the schmir/pypy-hacks branch with pubnub/pypy-hacks