summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzsquareplusc <cliechti@gmx.net>2020-09-14 04:07:55 +0200
committerGitHub <noreply@github.com>2020-09-14 04:07:55 +0200
commit9e9bcebc6dc6730e77c6290215ea3c449d5e453e (patch)
treea87e90fd94fb61d7b1c1922ef7f2ea680933a71c
parente99bda36b6f93b1a4232a96c9927e75aebd31580 (diff)
parentb92365a082b659459db78bc8b6fb509eb6737e8d (diff)
downloadpyserial-git-9e9bcebc6dc6730e77c6290215ea3c449d5e453e.tar.gz
Merge pull request #494 from kalvdans/dont-catch-our-own-exception
posix: Don't catch the SerialException we just raised
-rw-r--r--serial/serialposix.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/serial/serialposix.py b/serial/serialposix.py
index f31b99d..0e97d58 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)