Skip to content

run_coroutine_threadsafe document can not be reproduced #121075

@PaleNeutron

Description

@PaleNeutron

Documentation

https://docs.python.org/3/library/asyncio-task.html#asyncio.run_coroutine_threadsafe

My test code:

import asyncio


async def main():
    """main is async and started as normal with asyncio.run"""
    print("BEGIN main")

    loop = asyncio.get_running_loop()
    timeout = 3
    # Create a coroutine
    coro = asyncio.sleep(1, result=3)

    # Submit the coroutine to a given loop
    future = asyncio.run_coroutine_threadsafe(coro, loop)

    # Wait for the result with an optional timeout argument
    assert future.result(timeout) == 3


if __name__ == "__main__":
    asyncio.run(main())

Tested with Python 3.11.6 and Python 3.10.14, Both get TimeoutError

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions