Commit a3a1d169 authored by Jason Madden's avatar Jason Madden

Fix a possible TypeError in gevent.socket.wait. Fixes #635. Fixes #636.

parent 3696d569
......@@ -20,6 +20,8 @@ Unreleased
with large inputs. `bench_sendall.py`_ now performs about as well on
PyPy as it does on CPython, an improvement of 10x (from ~60MB/s to
~630MB/s). See this `pypy bug`_ for details.
- Fix a possible ``TypeError`` when calling ``gevent.socket.wait``.
Reported in #635 by lanstin.
.. _future: http://python-future.org
.. _bench_sendall.py: https://raw.githubusercontent.com/gevent/gevent/master/greentest/bench_sendall.py
......
......@@ -116,6 +116,7 @@ class _NONE(object):
return "<default value>"
_NONE = _NONE()
_timeout_error = timeout
def wait(io, timeout=None, timeout_exc=_NONE):
......@@ -140,7 +141,7 @@ def wait(io, timeout=None, timeout_exc=_NONE):
"""
assert io.callback is None, 'This socket is already used by another greenlet: %r' % (io.callback, )
if timeout is not None:
timeout_exc = timeout_exc if timeout_exc is not _NONE else timeout('timed out')
timeout_exc = timeout_exc if timeout_exc is not _NONE else _timeout_error('timed out')
timeout = Timeout.start_new(timeout, timeout_exc)
try:
......
......@@ -222,6 +222,30 @@ class TestCreateConnection(greentest.TestCase):
else:
raise AssertionError('create_connection did not raise socket.error as expected')
class TestFunctions(greentest.TestCase):
def test_wait_timeout(self):
# Issue #635
import gevent.socket
import gevent._socketcommon
orig_get_hub = gevent.socket.get_hub
class get_hub(object):
def wait(self, io):
gevent.sleep(10)
class io(object):
callback = None
gevent._socketcommon.get_hub = get_hub
try:
try:
gevent.socket.wait(io(), timeout=0.01)
except gevent.socket.timeout:
pass
else:
self.fail("Should raise timeout error")
finally:
gevent._socketcommon.get_hub = orig_get_hub
if __name__ == '__main__':
greentest.main()
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