From 23fa53786b142a66ef90a68d6799370b7559f8f0 Mon Sep 17 00:00:00 2001 From: Rotem Yaari Date: Mon, 7 May 2012 10:41:09 +0300 Subject: [PATCH] Handle EINTR in Stream.poll() --- rpyc/core/stream.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/rpyc/core/stream.py b/rpyc/core/stream.py index a7691467..ac4f65cf 100644 --- a/rpyc/core/stream.py +++ b/rpyc/core/stream.py @@ -36,13 +36,24 @@ def poll(self, timeout): """indicates whether the stream has data to read (within *timeout* seconds)""" try: - rl, _, _ = select([self], [], [], timeout) + rl, _, _ = self._select([self], [], [], timeout) except ValueError: # i got this once: "ValueError: file descriptor cannot be a negative integer (-1)" # let's translate it to select.error ex = sys.exc_info()[1] raise select_error(str(ex)) return bool(rl) + def _select(self, reads, writes, exc, timeout): + end_time = None if timeout is None else time.time() + timeout + while True: + try: + return select(reads, writes, exc, timeout) + except socket.error: + ex = sys.exc_info()[1] + if get_exc_errno(ex) != errno.EINTR: + raise + if end_time is not None: + timeout = max(0, end_time - time.time()) def read(self, count): """reads **exactly** *count* bytes, or raise EOFError