Skip to content

Commit

Permalink
cli: retrieve exception of applet task before finishing other work.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
whitequark committed Oct 21, 2023
1 parent b402e98 commit 5e113b4
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions software/glasgow/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5e113b4

Please sign in to comment.