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
Failing ensure_future still creates a Task #70739
Comments
When calling asyncio.ensure_future() on a coroutine, and if the loop is closed, ensure_future() will raise a RuntimeError. However, it still creates a Task, which will generate a RuntimeWarning that we can’t fix since there is no way to cancel the Task. Here is the code to reproduce the bug: import asyncio
l = asyncio.get_event_loop()
l.close()
async def foo():
pass try: # stderr: |
Sounds like an easy fix. Could you submit a patch? |
Reproduced on 3.11. |
So I just realized that the OP's description is slightly misleading. (Their code is spot on though!) The code does not create an unwaited-for *task*, assuming that "task" refers to the asyncio.Task class. What is created is a *coroutine* object that's never awaited (as the quoted RuntimeWarning message says: "coroutine 'foo' was never awaited"). So the thing that needs to be closed in the bowels of _ensure_future() is indeed the argument (coro_or_future), in case it is a coroutine object. |
Thanks Kumar for the fix! |
asyncio.ensure_future
did not close the coroutine #30288Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: