For what it's worth, this recent issue:  is somewhat related to the non-async aspect of 533. (generator func getting closed during __del__ and causing odd side-effects at seemingly random points in the execution flow)

The example code provided in that issue is contrived, and involves catching unconditional exceptions and recursing, but following the code flow in that situation feels unreasonably hard, and deciding if it's a python bug or not is even harder.

I'm not sure how easy an implementation of 533 would be that doesn't break a lot of existing code, but if one could be made, it might help make generator lifecycles more predictable.

On Tue, Jan 5, 2021 at 1:08 PM Senthil Kumaran <> wrote:
Hi Paul,

> Per PEP 525, I can call aclose coroutine method to cleanup the generator, but
> it requires the code iterating to be aware that that closing the generator is
> necessary.

How about treating this as a bug for the specific use case that you mentioned,
rather than a complete addition of " PEP 533 -- Deterministic cleanup for
iterators". I am not certain why PEP 533 was deffered.

I'd also suggest a documentation update if the details of aclose requirement is
mentioned only in a PEP and not in the documentation.

Thank you,
Python-Dev mailing list --
To unsubscribe send an email to
Message archived at
Code of Conduct: