diff options
author | zsquareplusc <cliechti@gmx.net> | 2020-09-14 04:07:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-14 04:07:55 +0200 |
commit | 9e9bcebc6dc6730e77c6290215ea3c449d5e453e (patch) | |
tree | a87e90fd94fb61d7b1c1922ef7f2ea680933a71c | |
parent | e99bda36b6f93b1a4232a96c9927e75aebd31580 (diff) | |
parent | b92365a082b659459db78bc8b6fb509eb6737e8d (diff) | |
download | pyserial-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.py | 22 |
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) |