We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 0633bfd + bb9b718 commit 476a1cdCopy full SHA for 476a1cd
1 file changed
pybricksdev/connections/pybricks.py
@@ -357,10 +357,15 @@ def handle_disconnect(state: ConnectionState):
357
disconnect_event.set()
358
359
with self.connection_state_observable.subscribe(handle_disconnect):
360
- done, pending = await asyncio.wait(
361
- {awaitable_task, disconnect_task},
362
- return_when=asyncio.FIRST_COMPLETED,
363
- )
+ try:
+ done, pending = await asyncio.wait(
+ {awaitable_task, disconnect_task},
+ return_when=asyncio.FIRST_COMPLETED,
364
+ )
365
+ except BaseException:
366
+ awaitable_task.cancel()
367
+ disconnect_task.cancel()
368
+ raise
369
370
for t in pending:
371
t.cancel()
0 commit comments