From 17660ee319e307a9f738cce7b120b4b76911512b Mon Sep 17 00:00:00 2001 From: Chris Liechti Date: Thu, 4 May 2017 23:39:05 +0200 Subject: [PATCH] posix: ignore more blocking errors and EINTR also for python 2.7 - 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 --- serial/serialposix.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/serial/serialposix.py b/serial/serialposix.py index bb2fa034..a465e3eb 100644 --- a/serial/serialposix.py +++ b/serial/serialposix.py @@ -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