Skip to content

gh-96037: Always insert TimeoutError when exit an expired asyncio.timeout() block#113819

Merged
serhiy-storchaka merged 3 commits into
python:mainfrom
serhiy-storchaka:asyncio-timeout-insert-timeout-error-in-context
Jan 10, 2024
Merged

gh-96037: Always insert TimeoutError when exit an expired asyncio.timeout() block#113819
serhiy-storchaka merged 3 commits into
python:mainfrom
serhiy-storchaka:asyncio-timeout-insert-timeout-error-in-context

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jan 8, 2024

Copy link
Copy Markdown
Member

If other exception was raised during exiting an expired asyncio.timeout() block, insert TimeoutError in the exception context just above the CancelledError.

…io.timeout() block

If other exception was raised during exiting an expired
asyncio.timeout() block, insert TimeoutError in the exception context
just above the CancelledError.

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this. Hopefully @iritkatriel does too. I got a little lost following the tests, hence my request for comments there. And there seems to be some debugging code "10" left?

Comment thread Lib/asyncio/timeouts.py Outdated
Comment thread Lib/asyncio/timeouts.py Outdated
# Since there are no new cancel requests, we're
# handling this.
raise TimeoutError from exc_val
if exc_type is exceptions.CancelledError:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think CancelledError is final. Maybe we should switch to isinstance()?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some code uses isinstance(), other code (in taskgroups.py and futures.py) uses is.

Are we going to backport this PR? If not, then perhaps it is better to change is to isinstance() in other PR before merging this PR. If yes, then we can include this change in this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a perf hack, but it makes things harder to reason about (what will happen if I raise a subclass of CancelledError? Who knows?).

I don't think we should backport this, such changes always trip some folks over.

Comment thread Lib/asyncio/timeouts.py Outdated
Comment thread Lib/asyncio/timeouts.py
Comment thread Lib/test/test_asyncio/test_timeouts.py Outdated
Comment thread Lib/test/test_asyncio/test_timeouts.py
Comment thread Lib/test/test_asyncio/test_timeouts.py
Comment thread Lib/test/test_asyncio/test_timeouts.py
Comment thread Lib/test/test_asyncio/test_timeouts.py
Comment thread Lib/test/test_asyncio/test_timeouts.py

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Go ahead and merge, let's not backport.

Comment thread Lib/asyncio/timeouts.py Outdated
# Since there are no new cancel requests, we're
# handling this.
raise TimeoutError from exc_val
if exc_type is exceptions.CancelledError:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a perf hack, but it makes things harder to reason about (what will happen if I raise a subclass of CancelledError? Who knows?).

I don't think we should backport this, such changes always trip some folks over.

Comment thread Lib/asyncio/timeouts.py
Comment thread Lib/asyncio/timeouts.py
@serhiy-storchaka
serhiy-storchaka merged commit aef4a12 into python:main Jan 10, 2024
@serhiy-storchaka
serhiy-storchaka deleted the asyncio-timeout-insert-timeout-error-in-context branch January 10, 2024 10:50
kulikjak pushed a commit to kulikjak/cpython that referenced this pull request Jan 22, 2024
…io.timeout() block (pythonGH-113819)

If other exception was raised during exiting an expired
asyncio.timeout() block, insert TimeoutError in the exception context
just above the CancelledError.
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
…io.timeout() block (pythonGH-113819)

If other exception was raised during exiting an expired
asyncio.timeout() block, insert TimeoutError in the exception context
just above the CancelledError.
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
…io.timeout() block (pythonGH-113819)

If other exception was raised during exiting an expired
asyncio.timeout() block, insert TimeoutError in the exception context
just above the CancelledError.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants