[issue37455] asyncio.run() error related to finalizing async generators

Sam Frances report at bugs.python.org
Sun Jun 30 19:55:50 EDT 2019


Sam Frances <sam at samfrances.uk> added the comment:

Apologies for the stray unused function in the example. It should have read:

```
import asyncio


async def count():
    try:
        i = 0
        while True:
            yield i
            i += 1
    finally:
        print("count() cleanup")


async def double(source):
    try:
        async for n in source:
            yield n * 2
    finally:
        print("double() cleanup")


async def main():
    async for i in double(count()):
        if i > 10:
            return
        print(i)

asyncio.run(main())
```

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37455>
_______________________________________


More information about the Python-bugs-list mailing list