-
-
Notifications
You must be signed in to change notification settings - Fork 353
Add exception message for easier debugging with Cancelled
#3232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Might be better to not use a string argument, instead pass like an enum + task name, then have |
I'm not so sure being introspectable is that important for figuring out why something was cancelled. Probably being more varied in what information we show (setting |
I'm somewhat inclined against setting An example usecase here is "I have dozens of I really love "collect and show everything" as an error-handling default, but when you get to 150k line tracebacks, programmatically determining what we can safely omit becomes very very important 😅 |
Alright, that makes sense as to why not to add more context for case 2, probably case 3 too. Too bad since a stack trace of the task that called I think providing at least an attribute with an enum is a good idea. I'm not sure what the best strategy for sum types in Python is (because some enum members sound like they would need extra context), but maybe we can get away with |
I'm now thinking of having three attributes Storing tracebacks makes me pretty nervous; it's easy to blow up memory use due to delayed garbage collection of all the extra objects they keep references to. It does sound nice to have as an opt-in debug mode, but I don't actually have a specific case in mind where it'd help. |
There are also use cases that rely on the GC so object finalizers get fired (including one of my own apps). |
This is not strictly speaking supported behavior for Python, and risky to rely on - you can get broken by CPython updates, or library changes, or PyPy having different GC semantics, etc. - but I agree that it's reasonable for Trio to avoid breaking such use-cases if we can. |
Occasionally we end up digging through logs trying to work out why something was cancelled, and eventually it occurred to me that Trio could help with this. I don't have a complete design proposal, but it would be great to handle each of three cases:
Nursery
raised an exception, including the name of the erroring taskCancelScope.cancel()
, including the name of the task in which this was calledreason: str | None = None
param, so that users can explicitly annotate why they cancelled somethingI think we could represent this as a string argument to
Cancelled
like any other exception message; the only tricky part will be threading it through all the cancellation-delivery machinery 🙂Comments and design input most welcome, of course!
The text was updated successfully, but these errors were encountered: