-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed
Labels
Description
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
Labels
Projects
Status
Done