diff options
author | nexcvon <nexcvon@users.noreply.github.com> | 2016-05-24 15:48:46 +0800 |
---|---|---|
committer | nexcvon <nexcvon@users.noreply.github.com> | 2016-05-24 15:48:46 +0800 |
commit | 50ec223ca3757d44db48201cd31e2182f1d8498a (patch) | |
tree | 1e16de808ca025fe00f07cf61cdf838d931dca58 | |
parent | 48e40e978203a3162339ee65e56ba243294493f2 (diff) | |
download | pyserial-git-50ec223ca3757d44db48201cd31e2182f1d8498a.tar.gz |
posix: retry if interrupted in Serial.read
Retry and recalculate timeout if interrupted in Serial.read.
see https://www.python.org/dev/peps/pep-0475.
-rw-r--r-- | serial/serialposix.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/serial/serialposix.py b/serial/serialposix.py index 5b33a33..cff4db1 100644 --- a/serial/serialposix.py +++ b/serial/serialposix.py @@ -464,14 +464,10 @@ class Serial(SerialBase, PlatformSpecific): 'device reports readiness to read but returned no data ' '(device disconnected or multiple access on port?)') read.extend(buf) - if timeout is not None: - timeout -= time.time() - start_time - if timeout <= 0: - break except OSError as e: # this is for Python 3.x where select.error is a subclass of # OSError ignore EAGAIN errors. all other errors are shown - if e.errno != errno.EAGAIN: + if e.errno != errno.EAGAIN and e.errno != errno.EINTR: raise SerialException('read failed: {}'.format(e)) except select.error as e: # this is for Python 2.x @@ -479,6 +475,10 @@ class Serial(SerialBase, PlatformSpecific): # see also http://www.python.org/dev/peps/pep-3151/#select if e[0] != errno.EAGAIN: raise SerialException('read failed: {}'.format(e)) + if timeout is not None: + timeout -= time.time() - start_time + if timeout <= 0: + break return bytes(read) def cancel_read(self): |