From cab3dabc81ecbf010d81ff38433db99c1f6d667c Mon Sep 17 00:00:00 2001 From: Chris Liechti Date: Wed, 7 Dec 2016 01:27:41 +0100 Subject: [PATCH] miniterm: change cancel impl. for console, fixes #174 the way select was used, was incompatible with the text io wrapper used by python3 for sys.stdin --- serial/tools/miniterm.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/serial/tools/miniterm.py b/serial/tools/miniterm.py index 7c68e9d1..14182f06 100644 --- a/serial/tools/miniterm.py +++ b/serial/tools/miniterm.py @@ -135,15 +135,12 @@ def cancel(self): elif os.name == 'posix': import atexit import termios - import select + import fcntl class Console(ConsoleBase): def __init__(self): super(Console, self).__init__() self.fd = sys.stdin.fileno() - # an additional pipe is used in getkey, so that the cancel method - # can abort the waiting getkey method - self.pipe_r, self.pipe_w = os.pipe() self.old = termios.tcgetattr(self.fd) atexit.register(self.cleanup) if sys.version_info < (3, 0): @@ -159,17 +156,13 @@ def setup(self): termios.tcsetattr(self.fd, termios.TCSANOW, new) def getkey(self): - ready, _, _ = select.select([self.enc_stdin, self.pipe_r], [], [], None) - if self.pipe_r in ready: - os.read(self.pipe_r, 1) - return c = self.enc_stdin.read(1) if c == unichr(0x7f): c = unichr(8) # map the BS key (which yields DEL) to backspace return c def cancel(self): - os.write(self.pipe_w, b"x") + fcntl.ioctl(self.fd, termios.TIOCSTI, b'\0') def cleanup(self): termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)