Issue
I'm looking how to close a nested async generator without fully iterating it. For example:
import asyncio
async def gen1():
yield 1
yield 2
async def gen2():
async for nr in gen1():
yield nr
async def main():
stream = gen2()
print(await stream.__anext__()) # 1
await stream.aclose()
asyncio.run(main())
However, this results in a RuntimeError
:
unhandled exception during asyncio.run() shutdown
task: <Task finished name='Task-2' coro=<<async_generator_athrow without __name__>()> exception=RuntimeError("can't send non-None value to a just-started coroutine")>
RuntimeError: can't send non-None value to a just-started coroutine
Solution
The original issue was present when testing with Python versions 3.7.4
and 3.8.0b4
. It has since been fixed in 3.8.0rc1
:
https://bugs.python.org/issue38013
Answered By - Jaanus Varus
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.