diff options
author | Chris Liechti <cliechti@gmx.net> | 2017-05-05 00:05:23 +0200 |
---|---|---|
committer | Chris Liechti <cliechti@gmx.net> | 2017-05-05 00:05:23 +0200 |
commit | 10d79d9dcd508a391162f1c1b68538e60e5e931e (patch) | |
tree | 4d3bdf5a3d3ebb812af31502466aea18b2e40c6e | |
parent | 17660ee319e307a9f738cce7b120b4b76911512b (diff) | |
download | pyserial-git-10d79d9dcd508a391162f1c1b68538e60e5e931e.tar.gz |
posix: ignore more blocking errors and EINTR in write just as in read
- catch all the errno's that BlockingIOError would cover
- catch EINTR
fixes #227
-rw-r--r-- | serial/serialposix.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/serial/serialposix.py b/serial/serialposix.py index a465e3e..278ce47 100644 --- a/serial/serialposix.py +++ b/serial/serialposix.py @@ -561,12 +561,20 @@ class Serial(SerialBase, PlatformSpecific): tx_len -= n except SerialException: raise - except OSError as v: - if v.errno != errno.EAGAIN: - raise SerialException('write failed: {}'.format(v)) - # still calculate and check timeout - if timeout.expired(): - raise writeTimeoutError + 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 + # 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('write failed: {}'.format(e)) + except select.error as e: + # this is for Python 2.x + # ignore BlockingIOErrors and EINTR. all errors are shown + # 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('write failed: {}'.format(e)) + if timeout.expired(): + raise writeTimeoutError return length - len(d) def flush(self): |