greenio: only trampoline when we block
https://github.com/eventlet/eventlet/pull/314
This commit is contained in:

committed by
Sergey Shepelev

parent
41bbe278d6
commit
863a1b7605
@@ -85,7 +85,7 @@ class GreenFileIO(_OriginalIOBase):
|
||||
except OSError as e:
|
||||
if get_errno(e) not in SOCKET_BLOCKING:
|
||||
raise IOError(*e.args)
|
||||
self._trampoline(self, read=True)
|
||||
self._trampoline(self, read=True)
|
||||
|
||||
def readall(self):
|
||||
buf = []
|
||||
@@ -98,7 +98,7 @@ class GreenFileIO(_OriginalIOBase):
|
||||
except OSError as e:
|
||||
if get_errno(e) not in SOCKET_BLOCKING:
|
||||
raise IOError(*e.args)
|
||||
self._trampoline(self, read=True)
|
||||
self._trampoline(self, read=True)
|
||||
|
||||
def readinto(self, b):
|
||||
up_to = len(b)
|
||||
|
43
tests/isolated/regular_file_readall.py
Normal file
43
tests/isolated/regular_file_readall.py
Normal file
@@ -0,0 +1,43 @@
|
||||
__test__ = False
|
||||
|
||||
if __name__ == '__main__':
|
||||
import eventlet
|
||||
eventlet.monkey_patch()
|
||||
|
||||
from eventlet.support import six
|
||||
import io
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
with tempfile.NamedTemporaryFile() as tmp:
|
||||
with io.open(tmp.name, "wb") as fp:
|
||||
fp.write(b"content")
|
||||
|
||||
# test BufferedReader.read()
|
||||
fd = os.open(tmp.name, os.O_RDONLY)
|
||||
fp = os.fdopen(fd, "rb")
|
||||
with fp:
|
||||
content = fp.read()
|
||||
assert content == b'content'
|
||||
|
||||
# test FileIO.read()
|
||||
fd = os.open(tmp.name, os.O_RDONLY)
|
||||
fp = os.fdopen(fd, "rb", 0)
|
||||
with fp:
|
||||
content = fp.read()
|
||||
assert content == b'content'
|
||||
|
||||
if six.PY3:
|
||||
# test FileIO.readall()
|
||||
fd = os.open(tmp.name, os.O_RDONLY)
|
||||
fp = os.fdopen(fd, "rb", 0)
|
||||
with fp:
|
||||
content = fp.readall()
|
||||
assert content == b'content'
|
||||
|
||||
# test FileIO.readall() (for Python 2 and Python 3)
|
||||
with io.open(tmp.name, "rb", 0) as fp:
|
||||
content = fp.readall()
|
||||
assert content == b'content'
|
||||
|
||||
print("pass")
|
@@ -528,3 +528,7 @@ def test_socketserver_selectors():
|
||||
|
||||
def test_blocking_select_methods_are_deleted():
|
||||
tests.run_isolated('patcher_blocking_select_methods_are_deleted.py')
|
||||
|
||||
|
||||
def test_regular_file_readall():
|
||||
tests.run_isolated('regular_file_readall.py')
|
||||
|
Reference in New Issue
Block a user