summaryrefslogtreecommitdiff
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
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
-rw-r--r--CHANGES.txt3
-rw-r--r--serial/serialposix.py42
2 files changed, 28 insertions, 17 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 8aa344f..35d3f65 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -444,6 +444,7 @@ Version 2.7 2012-nn-nn
- rfc2217: zero polls value (baudrate, data size, stop bits, parity) (Erik
Lundh)
- Posix: [Patch pyserial:28] Accept any speed on Linux
+- Posix: [Patch pyserial:29] PosixSerial.read() should "ignore" errno.EINTR
Bugfixes:
@@ -468,6 +469,6 @@ Bugfixes (win32):
- [Bug 3550043] on Window in tools global name 'GetLastError' is not defined
- [Bug pyserial:146] flush() does nothing in windows (despite docs)
- [Bug pyserial:144] com0com ports ignored due to missing "friendly name"
-- [Bug pyserial:152] Cannot configure port, some setting was wrong. can leave
+- [Bug pyserial:152] Cannot configure port, some setting was wrong. Can leave
port handle open but port not accessible
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):