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 <damien@micropython.org>
This commit is contained in:
@@ -275,6 +275,7 @@ class Pyboard:
|
|||||||
wait=0,
|
wait=0,
|
||||||
exclusive=True,
|
exclusive=True,
|
||||||
timeout=None,
|
timeout=None,
|
||||||
|
write_timeout=5,
|
||||||
):
|
):
|
||||||
self.in_raw_repl = False
|
self.in_raw_repl = False
|
||||||
self.use_raw_paste = True
|
self.use_raw_paste = True
|
||||||
@@ -293,6 +294,7 @@ class Pyboard:
|
|||||||
serial_kwargs = {
|
serial_kwargs = {
|
||||||
"baudrate": baudrate,
|
"baudrate": baudrate,
|
||||||
"timeout": timeout,
|
"timeout": timeout,
|
||||||
|
"write_timeout": write_timeout,
|
||||||
"interCharTimeout": 1,
|
"interCharTimeout": 1,
|
||||||
}
|
}
|
||||||
if serial.__version__ >= "3.3":
|
if serial.__version__ >= "3.3":
|
||||||
@@ -376,6 +378,12 @@ class Pyboard:
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
def enter_raw_repl(self, soft_reset=True, timeout_overall=10):
|
def enter_raw_repl(self, soft_reset=True, timeout_overall=10):
|
||||||
|
try:
|
||||||
|
self._enter_raw_repl_unprotected(soft_reset, timeout_overall)
|
||||||
|
except OSError as er:
|
||||||
|
raise PyboardError("could not enter raw repl: {}".format(er))
|
||||||
|
|
||||||
|
def _enter_raw_repl_unprotected(self, soft_reset, timeout_overall):
|
||||||
self.serial.write(b"\r\x03") # ctrl-C: interrupt any running program
|
self.serial.write(b"\r\x03") # ctrl-C: interrupt any running program
|
||||||
|
|
||||||
# flush input (without relying on serial.flushInput())
|
# flush input (without relying on serial.flushInput())
|
||||||
|
|||||||
Reference in New Issue
Block a user