Skip to content

Commit 4eab275

Browse files
committed
idf_monitor: Fix remaining case of Windows "console write fails" bug
Closes #1567
1 parent 19d3d25 commit 4eab275

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

tools/idf_monitor.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,17 @@ def __init__(self, output):
579579
self.handle = GetStdHandle(STD_ERROR_HANDLE if self.output == sys.stderr else STD_OUTPUT_HANDLE)
580580
self.matched = b''
581581

582+
def _output_write(self, data):
583+
# Windows 10 bug since the Fall Creators Update, sometimes writing to console randomly fails
584+
# (but usually succeeds afterwards, it seems.)
585+
# Ref https://github.com/espressif/esp-idf/issues/1136
586+
for tries in range(3):
587+
try:
588+
self.output.write(data)
589+
return
590+
except IOError:
591+
pass
592+
582593
def write(self, data):
583594
for b in data:
584595
l = len(self.matched)
@@ -597,18 +608,10 @@ def write(self, data):
597608
color |= FOREGROUND_INTENSITY
598609
SetConsoleTextAttribute(self.handle, color)
599610
else:
600-
self.output.write(self.matched) # not an ANSI color code, display verbatim
611+
self._output_write(self.matched) # not an ANSI color code, display verbatim
601612
self.matched = b''
602613
else:
603-
try:
604-
self.output.write(b)
605-
except IOError:
606-
# Windows 10 bug since the Fall Creators Update, sometimes writing to console randomly fails
607-
# (but usually succeeds the second time, it seems.) Ref https://github.com/espressif/esp-idf/issues/1136
608-
try:
609-
self.output.write(b)
610-
except IOError:
611-
pass
614+
self._output_write(b)
612615
self.matched = b''
613616

614617
def flush(self):

0 commit comments

Comments
 (0)