Skip to content

Commit

Permalink
posix: ignore more blocking errors and EINTR also for python 2.7
Browse files Browse the repository at this point in the history
- catch all the errno's that BlockingIOError would cover
- and catch EINTR in for both blocks, for Py 2.7 and 3.x

fixes #227
  • Loading branch information
zsquareplusc committed May 4, 2017
1 parent c795c4d commit 17660ee
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions serial/serialposix.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,14 +503,15 @@ def read(self, size=1):
read.extend(buf)
except OSError as e:
# this is for Python 3.x where select.error is a subclass of
# OSError ignore EAGAIN errors. all other errors are shown
if e.errno != errno.EAGAIN and e.errno != errno.EINTR:
# OSError ignore BlockingIOErrors and EINTR. other errors are shown
# https://www.python.org/dev/peps/pep-0475.
if e.errno not in (errno.EAGAIN, errno.EALREADY, errno.EWOULDBLOCK, errno.EINPROGRESS, errno.EINTR):
raise SerialException('read failed: {}'.format(e))
except select.error as e:
# this is for Python 2.x
# ignore EAGAIN errors. all other errors are shown
# ignore BlockingIOErrors and EINTR. all errors are shown
# see also http://www.python.org/dev/peps/pep-3151/#select
if e[0] != errno.EAGAIN:
if e[0] not in (errno.EAGAIN, errno.EALREADY, errno.EWOULDBLOCK, errno.EINPROGRESS, errno.EINTR)):
raise SerialException('read failed: {}'.format(e))
if timeout.expired():
break
Expand Down

0 comments on commit 17660ee

Please sign in to comment.