Commit 1f6b31f7 authored by Jason Madden's avatar Jason Madden

Fix a regression introduced with PyPy support in 715a7071 that caused the...

Fix a regression introduced with PyPy support in 715a7071 that caused the timeout to be ignored for socket.makefile objects under Python 3. Fixes #644
parent bd9621a6
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
- Make ``SIGCHLD`` handlers specified to ``signal.signal`` work with - Make ``SIGCHLD`` handlers specified to ``signal.signal`` work with
the child watchers that are used by default. Also make the child watchers that are used by default. Also make
``os.waitpid`` work with a first argument of -1. ``os.waitpid`` work with a first argument of -1.
- Under Python 2, any timeout set on a socket would be ignored when
using the results of ``socket.makefile``. Reported in :issue:`644`
by Karan Lyons.
1.1b3 (Aug 16, 2015) 1.1b3 (Aug 16, 2015)
==================== ====================
......
...@@ -234,7 +234,8 @@ class socket(object): ...@@ -234,7 +234,8 @@ class socket(object):
# socket (hence creating a new instance) # socket (hence creating a new instance)
# 2) The resulting fileobject must keep the timeout in order # 2) The resulting fileobject must keep the timeout in order
# to be compatible with the stdlib's socket.makefile. # to be compatible with the stdlib's socket.makefile.
fobj = _fileobject(type(self)(_sock=self._sock), mode, bufsize) # Pass self as _sock to preserve timeout.
fobj = _fileobject(type(self)(_sock=self), mode, bufsize)
if PYPY: if PYPY:
self._sock._drop() self._sock._drop()
return fobj return fobj
......
...@@ -185,6 +185,23 @@ class TestTCP(greentest.TestCase): ...@@ -185,6 +185,23 @@ class TestTCP(greentest.TestCase):
fd.close() fd.close()
acceptor.join() acceptor.join()
def test_makefile_timeout(self):
def accept_once():
conn, addr = self.listener.accept()
try:
time.sleep(0.3)
finally:
conn.close() # for pypy
acceptor = Thread(target=accept_once)
client = self.create_connection()
client.settimeout(0.1)
fd = client.makefile(mode='rb')
self.assertRaises(socket.error, fd.readline)
client.close()
fd.close()
def test_attributes(self): def test_attributes(self):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
self.assertEqual(socket.AF_INET, s.type) self.assertEqual(socket.AF_INET, s.type)
......
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