Skip to content
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

asyncio.wait_for() doesn't raise builtin TimeoutError #110703

Closed
paskozdilar opened this issue Oct 11, 2023 · 5 comments
Closed

asyncio.wait_for() doesn't raise builtin TimeoutError #110703

paskozdilar opened this issue Oct 11, 2023 · 5 comments
Labels
docs Documentation in the Doc dir

Comments

@paskozdilar
Copy link
Contributor

paskozdilar commented Oct 11, 2023

Documentation

The documentation page about asyncio.wait_for() function says that:

If a timeout occurs, it cancels the task and raises TimeoutError.

The TimeoutError hyperlink leads to the built-in exception "TimeoutError", which would lead any sane user to think that asyncio.wait_for() raises builtin TimeoutError.

However, it doesn't:

#!/usr/bin/env python3

import asyncio


async def main():
    try:
        await asyncio.wait_for(asyncio.sleep(100), timeout=1)
    except TimeoutError:
        print('timeout error')
    except Exception as exc:
        print('not a timeout error:', type(exc))


asyncio.run(main())

The above program prints:

not a timeout error: <class 'asyncio.exceptions.TimeoutError'>

Documentation should be changed to reflect what really happens in Python.

Linked PRs

@paskozdilar paskozdilar added the docs Documentation in the Doc dir label Oct 11, 2023
@paskozdilar paskozdilar changed the title asyncio.wait_for() doesn't raise TimeoutError asyncio.wait_for() doesn't raise builtin TimeoutError Oct 11, 2023
@Eclips4
Copy link
Member

Eclips4 commented Oct 11, 2023

Hello!
In 3.11+ it's already fixed: #86579
For 3.10 and other versions the documentation is correct:

If a timeout occurs, it cancels the task and raises asyncio.TimeoutError.

(from https://docs.python.org/3.10/library/asyncio-task.html#asyncio.wait_for)

So, seems that you reading docs for new versions, but in fact using a old one :)

@Eclips4 Eclips4 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2023
@paskozdilar
Copy link
Contributor Author

Ah, you're right.

I assumed nothing has changed because I expected a note, something like:

Changed in version 3.11: Raises builtin TimeoutError instead of asyncio.TimeoutError

Usually that kind of note follow any backwards-incompatible change.

Maybe it would be good idea to add that, it could save future readers from the same confusion I had.

Anyways, thanks for the quick reply :)

@terryjreedy terryjreedy reopened this Oct 11, 2023
@terryjreedy
Copy link
Member

Pending a clear decision otherwise, I think the suggested line immediately above should be added.

@kumaraditya303
Copy link
Contributor

Feel free to send a PR!

@paskozdilar
Copy link
Contributor Author

I've created the PR.

Thank you for the opportunity to contribute to CPython :)

willingc pushed a commit that referenced this issue Oct 13, 2023
* Remove redundant versionchanged

* Add missing versionchanged

* Update Doc/library/asyncio-task.rst

Co-authored-by: Kumar Aditya <kumaraditya@python.org>

---------

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 13, 2023
…GH-110818)

* Remove redundant versionchanged

* Add missing versionchanged

* Update Doc/library/asyncio-task.rst

Co-authored-by: Kumar Aditya <kumaraditya@python.org>

---------

(cherry picked from commit f81e36f)

Co-authored-by: paskozdilar <53006174+paskozdilar@users.noreply.github.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 13, 2023
…GH-110818)

* Remove redundant versionchanged

* Add missing versionchanged

* Update Doc/library/asyncio-task.rst

Co-authored-by: Kumar Aditya <kumaraditya@python.org>

---------

(cherry picked from commit f81e36f)

Co-authored-by: paskozdilar <53006174+paskozdilar@users.noreply.github.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
willingc pushed a commit that referenced this issue Oct 13, 2023
…0818) (#110826)

gh-110703: Add asyncio.wait_for() change notes for 3.11 (GH-110818)

* Remove redundant versionchanged

* Add missing versionchanged

* Update Doc/library/asyncio-task.rst



---------

(cherry picked from commit f81e36f)

Co-authored-by: paskozdilar <53006174+paskozdilar@users.noreply.github.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
willingc pushed a commit that referenced this issue Oct 13, 2023
…0818) (#110827)

gh-110703: Add asyncio.wait_for() change notes for 3.11 (GH-110818)

* Remove redundant versionchanged

* Add missing versionchanged

* Update Doc/library/asyncio-task.rst



---------

(cherry picked from commit f81e36f)

Co-authored-by: paskozdilar <53006174+paskozdilar@users.noreply.github.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
…GH-110818)

* Remove redundant versionchanged

* Add missing versionchanged

* Update Doc/library/asyncio-task.rst

Co-authored-by: Kumar Aditya <kumaraditya@python.org>

---------

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
…GH-110818)

* Remove redundant versionchanged

* Add missing versionchanged

* Update Doc/library/asyncio-task.rst

Co-authored-by: Kumar Aditya <kumaraditya@python.org>

---------

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

4 participants