summaryrefslogtreecommitdiff
path: root/serial/serialposix.py
diff options
context:
space:
mode:
authorChris Liechti <cliechti@gmx.net>2016-05-15 23:35:05 +0200
committerChris Liechti <cliechti@gmx.net>2016-05-15 23:35:05 +0200
commit42ab2b4b36b931a9e1aa946d78931e1e915a9c39 (patch)
tree75c8e4eab463c7e249c931e43c3fbecd4222f75c /serial/serialposix.py
parentc20c373d854504541d4ce22bdbe308bfc1cddb42 (diff)
downloadpyserial-git-42ab2b4b36b931a9e1aa946d78931e1e915a9c39.tar.gz
posix: implement cancel_read
Diffstat (limited to 'serial/serialposix.py')
-rw-r--r--serial/serialposix.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/serial/serialposix.py b/serial/serialposix.py
index 72ea9b0..47f869a 100644
--- a/serial/serialposix.py
+++ b/serial/serialposix.py
@@ -269,6 +269,7 @@ class Serial(SerialBase, PlatformSpecific):
else:
raise
self.reset_input_buffer()
+ self.pipe_abort_read_r, self.pipe_abort_read_w = os.pipe()
def _reconfigure_port(self, force_update=False):
"""Set communication parameters on opened port."""
@@ -435,7 +436,10 @@ class Serial(SerialBase, PlatformSpecific):
while len(read) < size:
try:
start_time = time.time()
- ready, _, _ = select.select([self.fd], [], [], timeout)
+ 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)
+ break
# If select was used with a timeout, and the timeout occurs, it
# returns with empty lists -> thus abort read operation.
# For timeout == 0 (non-blocking operation) also abort when
@@ -470,6 +474,9 @@ class Serial(SerialBase, PlatformSpecific):
raise SerialException('read failed: {}'.format(e))
return bytes(read)
+ def cancel_read(self):
+ os.write(self.pipe_abort_read_w, b"x")
+
def write(self, data):
"""Output the given byte string over the serial port."""
if not self.is_open: