Skip to content

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

@paskozdilar

Description

@paskozdilar

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions