[issue41229] Asynchronous generator memory leak

Nathaniel Smith report at bugs.python.org
Sun Jul 19 06:17:19 EDT 2020


Nathaniel Smith <njs at pobox.com> added the comment:

Oh! I see it. This is actually working as intended.

What's happening is that the event loop will clean up async generators when they're garbage collected... but, this requires that the event loop get a chance to run. In the demonstration program, the main task creates lots of async generator objects, but never returns to the main loop. So they're all queued up to be collected, but it can't actually happen until you perform a real async operation. For example, try adding 'await asyncio.sleep(1)` before the input() call so that the event loop has a chance to run, and you'll see that the objects are collected immediately.

So this is a bit tricky, but this is actually expected behavior, and falls under the general category of "don't block the event loop, it will break stuff".

----------
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

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


More information about the Python-bugs-list mailing list