trio icon indicating copy to clipboard operation
trio copied to clipboard

Make it easier to tell where a Cancelled exception came from

Open njsmith opened this issue 7 years ago • 4 comments

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.)

njsmith avatar Feb 11 '17 02:02 njsmith

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 avatar Mar 12 '19 10:03 oremanj

@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".

sorcio avatar Mar 12 '19 13:03 sorcio

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.

smurfix avatar Mar 12 '19 13:03 smurfix

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 :)

mchhoy avatar May 12 '21 04:05 mchhoy