trio
trio copied to clipboard
Make it easier to tell where a Cancelled exception came from
Right now repr(exc)
just gives Cancelled()
which is not so helpful when trying to debug. Maybe something like <Cancelled, scope 3 in task some_func-3>
?
(Even nicer if we could provide line numbers, but I think that would be expensive? Also misleading when the scope is hidden inside open_nursery
or move_on_at
.)
Tasks have had names for a while, and Cancelled exceptions don't know what scope will catch them anymore, so I'm not sure there's anything left to be done here.
@oremanj I think this is still relevant, or at least deserves a new proposal. It's still true that Cancelled
exceptions are a bit too anonymous when debugging, and adding extra context info would help "user happiness".
IMHO the way to fix this is to store the stack of the caller of the .cancel
method so that the actual Cancelled
exception can use it in a raise from
or similar.
Hi, I just spent a few hours debugging an issue where instead of:
await trio.sleep_until(x)
I had typed:
await trio.move_on_after(x)
And this was causing some phantom cancellations - something like this may have helped :)