Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TimeoutError not raised by 'timeout' context manager when "side errors" occur #96037

Closed
Labels
3.11only security fixes3.12only security fixestopic-asynciotype-featureA feature request or enhancement
@gvanrossum

Description

@gvanrossum

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

No one assigned

    Labels

    3.11only security fixes3.12only security fixestopic-asynciotype-featureA feature request or enhancement

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp