Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug #182: Stream uses select() and it is prone to its limitations #183

Merged
merged 1 commit into from
Feb 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions rpyc/core/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import time
import errno
from rpyc.lib import safe_import
from rpyc.lib.compat import select, select_error, BYTES_LITERAL, get_exc_errno, maxint
from rpyc.lib.compat import poll, select_error, BYTES_LITERAL, get_exc_errno, maxint
win32file = safe_import("win32file")
win32pipe = safe_import("win32pipe")
msvcrt = safe_import("msvcrt")
Expand Down Expand Up @@ -36,9 +36,11 @@ def poll(self, timeout):
"""indicates whether the stream has data to read (within *timeout*
seconds)"""
try:
p = poll() # from lib.compat, it may be a select object on non-Unix platforms
p.register(self.fileno(), "r")
while True:
try:
rl, _, _ = select([self], [], [], timeout)
rl = p.poll(timeout)
except select_error:
ex = sys.exc_info()[1]
if ex.args[0] == errno.EINTR:
Expand All @@ -48,8 +50,10 @@ def poll(self, timeout):
else:
break
except ValueError:
# i get this some times: "ValueError: file descriptor cannot be a negative integer (-1)"
# let's translate it to select.error
# if the underlying call is a select(), then the following errors may happen:
# - "ValueError: filedescriptor cannot be a negative integer (-1)"
# - "ValueError: filedescriptor out of range in select()"
# let's translate them to select.error
ex = sys.exc_info()[1]
raise select_error(str(ex))
return bool(rl)
Expand Down