summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzsquareplusc <cliechti@gmx.net>2016-05-28 23:54:15 +0200
committerzsquareplusc <cliechti@gmx.net>2016-05-28 23:54:15 +0200
commitfc264b85c87a6b7872f6e249ad1018567d85df8f (patch)
treeb13b1d840036548dcd982b3d4968f3e9b1441e4c
parentc55b5ac2ce72f9e65c2d69fc00e596ce5811894a (diff)
parent50ec223ca3757d44db48201cd31e2182f1d8498a (diff)
downloadpyserial-git-fc264b85c87a6b7872f6e249ad1018567d85df8f.tar.gz
Merge pull request #118 from nexcvon/patch-1
posix: retry if interrupted in Serial.read
-rw-r--r--serial/serialposix.py10
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):