From 2e43d107b476783288e045d07e51711c92a285be Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 24 Jul 2019 19:29:08 +0800 Subject: [PATCH] idf_monitor: Ignore OS-level errors writing to Windows Console Windows Console write or flush may fail (throwing WindowsError, a subclass of OSError) if the data written can't be displayed. This may be the case if the serial port is producing garbage bytes. Ignore the error, in the hope that the serial port may "come good" and write non-garbage later. --- tools/idf_monitor.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/idf_monitor.py b/tools/idf_monitor.py index 8fdcecd83..2b5b81ad8 100755 --- a/tools/idf_monitor.py +++ b/tools/idf_monitor.py @@ -899,10 +899,13 @@ if os.name == 'nt': self.output.write(data.decode()) else: self.output.write(data) - except IOError: + except (IOError, OSError): # Windows 10 bug since the Fall Creators Update, sometimes writing to console randomly throws # an exception (however, the character is still written to the screen) - # Ref https://github.com/espressif/esp-idf/issues/1136 + # Ref https://github.com/espressif/esp-idf/issues/1163 + # + # Also possible for Windows to throw an OSError error if the data is invalid for the console + # (garbage bytes, etc) pass def write(self, data): @@ -939,7 +942,12 @@ if os.name == 'nt': self.matched = b'' def flush(self): - self.output.flush() + try: + self.output.flush() + except OSError: + # Account for Windows Console refusing to accept garbage bytes (serial noise, etc) + pass + if __name__ == "__main__": main()