Skip to content

Commit

Permalink
Fixed bug #182: Stream uses select() and it is prone to its limitations
Browse files Browse the repository at this point in the history
  • Loading branch information
Giuseppe Lo Presti committed Dec 11, 2015
1 parent 7599ccf commit 28ef9b6
Showing 1 changed file with 8 additions and 4 deletions.
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

0 comments on commit 28ef9b6

Please sign in to comment.