Devin Fee <de...@devinfee.com> added the comment:
I've worked around this problem by doing something like this: async def close_cancelling(agen): while True: try: task = asyncio.ensure_future(agen.__anext__()) await task yield task.result() except (GeneratorExit, StopAsyncIteration): await agen.aclose() task.cancel() break async def run(): try: async for v in close_cancelling(agen): received.append(v) except asyncio.CancelledError: # handle finalization pass Though, I'm still convinced that `aclose()` should call raise `StopAsyncIteration` on `agen.ag_await` ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue34730> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com