Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Description
Consider something like this:
asyncwithasyncio.timeout(1):try:awaitasyncio.sleep(2)# Will be interrupted after 1 secondfinally:1/0# Crash in cleanup
This will reportZeroDivisionError
but suppresses the fact that it happened during cleanup. Once#95761 lands the same problem will happen if thetry/finally
block happens to be in a task created usingTaskGroup
.
For end users who are looking why their code crashes it may be useful to know that thetimeout
context manager decided to cancel the thread, and that their crash was induced by the cancellation.
There are various ways we could solve this -- e.g. we might consider raising anExceptionGroup
that combinesTimeoutError
with the crash exception, but that would lead people to believe that they have to writeexcept* TimeoutError
to catch timeouts, and we don't want that (especially not since in 3.11 they don't have to).
I discussed this with@iritkatriel and she proposed that thetimeout
context manager could add anote to the crash exception (seePEP 678). For maximal usability the note should probably dig up the filename and linenumber of the caller and add those to its error message, so the note would read something like"Timed out at file <file>, line <line>"
(details TBD by whoever writes a PR for this).
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status