summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--serial/serialposix.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/serial/serialposix.py b/serial/serialposix.py
index 334ba9f..d5d6397 100644
--- a/serial/serialposix.py
+++ b/serial/serialposix.py
@@ -548,16 +548,6 @@ class Serial(SerialBase, PlatformSpecific):
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 OSError as e:
# this is for Python 3.x where select.error is a subclass of
# OSError ignore BlockingIOErrors and EINTR. other errors are shown
@@ -570,6 +560,18 @@ class Serial(SerialBase, PlatformSpecific):
# see also http://www.python.org/dev/peps/pep-3151/#select
if e[0] not in (errno.EAGAIN, errno.EALREADY, errno.EWOULDBLOCK, errno.EINPROGRESS, errno.EINTR):
raise SerialException('read failed: {}'.format(e))
+ else:
+ # 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)
+
if timeout.expired():
break
return bytes(read)