summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Liechti <cliechti@gmx.net>2016-06-03 23:52:34 +0200
committerChris Liechti <cliechti@gmx.net>2016-06-03 23:52:34 +0200
commit68cecce2bfb35faf547d996fdd55d5ffb6642dcf (patch)
treec30d385865422cf7ab80153f2d5f778f47ca4ddf
parent900a219747936cbb4e9aef424dd226b8314657a1 (diff)
downloadpyserial-git-68cecce2bfb35faf547d996fdd55d5ffb6642dcf.tar.gz
posix: make cancel-pipes non-blocking and read more bytes to "clear" pipe
- may help to clear up when cancel_read/write was called multiple times - does no solve that one future read/write call is canceled
-rw-r--r--serial/serialposix.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/serial/serialposix.py b/serial/serialposix.py
index cff4db1..28164d8 100644
--- a/serial/serialposix.py
+++ b/serial/serialposix.py
@@ -271,6 +271,8 @@ class Serial(SerialBase, PlatformSpecific):
self.reset_input_buffer()
self.pipe_abort_read_r, self.pipe_abort_read_w = os.pipe()
self.pipe_abort_write_r, self.pipe_abort_write_w = os.pipe()
+ fcntl.fcntl(self.pipe_abort_read_r, fcntl.F_SETFL, os.O_NONBLOCK)
+ fcntl.fcntl(self.pipe_abort_write_r, fcntl.F_SETFL, os.O_NONBLOCK)
def _reconfigure_port(self, force_update=False):
"""Set communication parameters on opened port."""
@@ -445,7 +447,7 @@ class Serial(SerialBase, PlatformSpecific):
start_time = time.time()
ready, _, _ = select.select([self.fd, self.pipe_abort_read_r], [], [], timeout)
if self.pipe_abort_read_r in ready:
- os.read(self.pipe_abort_read_r, 1)
+ os.read(self.pipe_abort_read_r, 1000)
break
# If select was used with a timeout, and the timeout occurs, it
# returns with empty lists -> thus abort read operation.
@@ -511,7 +513,7 @@ class Serial(SerialBase, PlatformSpecific):
raise writeTimeoutError
abort, ready, _ = select.select([self.pipe_abort_write_r], [self.fd], [], timeleft)
if abort:
- os.read(self.pipe_abort_write_r, 1)
+ os.read(self.pipe_abort_write_r, 1000)
break
if not ready:
raise writeTimeoutError