From 5f3b9876b8088f89f5223484ad000cb4480d03f6 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 21 Mar 2017 16:08:06 +0800 Subject: [PATCH] idf_monitor: Fix issues using Ctrl-F/Ctrl-A/gdb with older pyserial Previously error was "AttributeError: 'Console' object has no attribute 'cancel'" --- tools/idf_monitor.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/idf_monitor.py b/tools/idf_monitor.py index a8ddf77e7..824a2f8e1 100644 --- a/tools/idf_monitor.py +++ b/tools/idf_monitor.py @@ -148,7 +148,15 @@ class ConsoleReader(StoppableThread): self.console.cleanup() def _cancel(self): - self.console.cancel() + if hasattr(self.console, "cancel"): + self.console.cancel() + elif os.name == 'posix': + # this is the way cancel() is implemented in pyserial 3.1 or newer, + # older pyserial doesn't have this method, hence this hack. + # + # on Windows there is a different (also hacky) fix, applied above. + import fcntl, termios + fcntl.ioctl(self.console.fd, termios.TIOCSTI, b'\0') class SerialReader(StoppableThread): """ Read serial data from the serial port and push to the