Skip to content

Commit 52f055f

Browse files
committed
add proper handling of the new hub errors in the stay-connected code
1 parent f4dede9 commit 52f055f

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

pybricksdev/cli/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ async def reconnect_hub():
254254

255255
await hub.connect()
256256
# re-enable echoing of the hub's stdout
257+
hub.log_file = None
258+
hub.output = []
259+
hub._stdout_buf.clear()
260+
hub._stdout_line_queue = asyncio.Queue()
257261
hub.print_output = True
258262
hub._enable_line_handler = True
259263
return hub
@@ -284,13 +288,16 @@ async def reconnect_hub():
284288
else:
285289
exit()
286290

291+
except HubPowerButtonPressedError:
292+
try:
293+
await hub._wait_for_user_program_stop(5)
294+
except HubDisconnectError:
295+
hub = await reconnect_hub()
296+
287297
except HubDisconnectError:
288298
# let terminal cool off before making a new prompt
289299
await asyncio.sleep(0.3)
290-
hub = reconnect_hub()
291-
292-
except HubPowerButtonPressedError:
293-
hub._wait_for_user_program_stop(5)
300+
hub = await reconnect_hub()
294301

295302
finally:
296303
await hub.disconnect()

0 commit comments

Comments
 (0)