From 5e113b42f189450d82c20d4cd5c512b59aa56c92 Mon Sep 17 00:00:00 2001 From: Catherine Date: Sat, 21 Oct 2023 16:32:00 +0000 Subject: [PATCH] cli: retrieve exception of applet task before finishing other work. Otherwise asyncio will print a very long backtrace corresponding to the applet task (without any useful information) if, most commonly, the device was surprise unplugged and all of the other tasks that need USB communication fail. After this commit, finally, this works as it should: $ glasgow run benchmark -c 1000000000 I: g.device.hardware: generating bitstream ID 6b120f4f94cf4ccd95c51417abc09069 I: g.cli: running handler for applet 'benchmark' I: g.applet.internal.benchmark: running benchmark mode source for 953.674 MiB E: g.cli: device disconnected --- software/glasgow/cli.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/software/glasgow/cli.py b/software/glasgow/cli.py index 4649217c9..96c909c50 100644 --- a/software/glasgow/cli.py +++ b/software/glasgow/cli.py @@ -681,6 +681,10 @@ async def wait_for_sigint(): task.cancel() await asyncio.wait(tasks, return_when=asyncio.ALL_COMPLETED) + # If the applet task has raised an exception, retrieve it here in case any of the await + # statements above will fail; if we don't, asyncio will unnecessarily complain. + applet_task.exception() + if do_trace: await device.write_register(target.analyzer.addr_done, 1) await analyzer_task