Skip to content

Commit dea3035

Browse files
committed
tools/pyboard.py: Add write_timeout and catch errors in enter_raw_repl.
If the USB serial device locks up, then writes to that device can hang forever. That can make the test runner `tests/run-tests.py` lock up, among other problems. This commit introduces a 5 second write-timeout, and catches any OSError's raised during `enter_raw_repl()`. Now, if a USB serial device locks up, `enter_raw_repl()` will eventually raise an exception. Signed-off-by: Damien George <[email protected]>
1 parent b1c947a commit dea3035

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tools/pyboard.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ def __init__(
275275
wait=0,
276276
exclusive=True,
277277
timeout=None,
278+
write_timeout=5,
278279
):
279280
self.in_raw_repl = False
280281
self.use_raw_paste = True
@@ -293,6 +294,7 @@ def __init__(
293294
serial_kwargs = {
294295
"baudrate": baudrate,
295296
"timeout": timeout,
297+
"write_timeout": write_timeout,
296298
"interCharTimeout": 1,
297299
}
298300
if serial.__version__ >= "3.3":
@@ -376,6 +378,12 @@ def read_until(
376378
return data
377379

378380
def enter_raw_repl(self, soft_reset=True, timeout_overall=10):
381+
try:
382+
self._enter_raw_repl_unprotected(soft_reset, timeout_overall)
383+
except OSError as er:
384+
raise PyboardError("could not enter raw repl: {}".format(er))
385+
386+
def _enter_raw_repl_unprotected(self, soft_reset, timeout_overall):
379387
self.serial.write(b"\r\x03") # ctrl-C: interrupt any running program
380388

381389
# flush input (without relying on serial.flushInput())

0 commit comments

Comments
 (0)