summaryrefslogtreecommitdiff
path: root/serial
diff options
context:
space:
mode:
authorcliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2013-10-11 14:31:13 +0000
committercliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2013-10-11 14:31:13 +0000
commitc94ebec4ea682bb5c174b0986bc24d726f7213bc (patch)
treebafb7cf444b49db0bb7e34d1fdfa846db5bbdb42 /serial
parent080191f5522c51ca3bac8f5fce0261affda01c80 (diff)
downloadpyserial-c94ebec4ea682bb5c174b0986bc24d726f7213bc.tar.gz
[Patch pyserial:29] PosixSerial.read() should "ignore" errno.EINTR
git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@470 f19166aa-fa4f-0410-85c2-fa1106f25c8a
Diffstat (limited to 'serial')
-rw-r--r--serial/serialposix.py42
1 files changed, 26 insertions, 16 deletions
diff --git a/serial/serialposix.py b/serial/serialposix.py
index 8d93c59..e1abce3 100644
--- a/serial/serialposix.py
+++ b/serial/serialposix.py
@@ -457,22 +457,32 @@ class PosixSerial(SerialBase):
if not self._isOpen: raise portNotOpenError
read = bytearray()
while len(read) < size:
- ready,_,_ = select.select([self.fd],[],[], self._timeout)
- # If select was used with a timeout, and the timeout occurs, it
- # returns with empty lists -> thus abort read operation.
- # For timeout == 0 (non-blocking operation) also abort when there
- # is nothing to read.
- if not ready:
- break # timeout
- buf = os.read(self.fd, size-len(read))
- # read should always return some data as select reported it was
- # ready to read when we get to this point.
- if not buf:
- # Disconnected devices, at least on Linux, show the
- # behavior that they are always ready to read immediately
- # but reading returns nothing.
- raise SerialException('device reports readiness to read but returned no data (device disconnected?)')
- read.extend(buf)
+ try:
+ ready,_,_ = select.select([self.fd],[],[], self._timeout)
+ # If select was used with a timeout, and the timeout occurs, it
+ # returns with empty lists -> thus abort read operation.
+ # For timeout == 0 (non-blocking operation) also abort when there
+ # is nothing to read.
+ if not ready:
+ break # timeout
+ buf = os.read(self.fd, size-len(read))
+ # read should always return some data as select reported it was
+ # ready to read when we get to this point.
+ if not buf:
+ # Disconnected devices, at least on Linux, show the
+ # behavior that they are always ready to read immediately
+ # but reading returns nothing.
+ raise SerialException('device reports readiness to read but returned no data (device disconnected or multiple access on port?)')
+ read.extend(buf)
+ except select.error, e:
+ # ignore EAGAIN errors. all other errors are shown
+ # see also http://www.python.org/dev/peps/pep-3151/#select
+ if e[0] != errno.EAGAIN:
+ raise SerialException('read failed: %s' % (e,))
+ except OSError, e:
+ # ignore EAGAIN errors. all other errors are shown
+ if e.errno != errno.EAGAIN:
+ raise SerialException('read failed: %s' % (e,))
return bytes(read)
def write(self, data):