[issue44518] Finalization of non-exhausted asynchronous generators is deferred
Serhiy Storchaka
report at bugs.python.org
Mon Jun 28 12:40:46 EDT 2021
Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:
Inlined asyncio.run(func()) is roughly equivalent to the following code:
loop = asyncio.new_event_loop()
loop.run_until_complete(func())
loop.run_until_complete(loop.shutdown_asyncgens())
loop.close()
If comment out loop.run_until_complete(loop.shutdown_asyncgens()) I get the following output:
finalize outer
Task was destroyed but it is pending!
task: <Task pending name='Task-2' coro=<<async_generator_athrow without __name__>()>>
END
No "finalize inner" but a warning about pending task instead.
On other hand, the following code
for _ in func().__await__(): pass
produces the output in expected order:
finalize inner
finalize outer
END
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44518>
_______________________________________
More information about the Python-bugs-list
mailing list