This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author martin.panter
Recipients ezio.melotti, martin.panter, ncoghlan, pitrou, rhettinger, serhiy.storchaka
Date 2015-09-06.22:13:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1441577590.9.0.317537102647.issue25014@psf.upfronthosting.co.za>
In-reply-to
Content
I had also thought of this kind of function, but I dismissed it because it would either have to rely on garbage collection or an explicit close() call to close the generator in case the iteration is aborted. I think it might need some kind of “with-for” combined statement added to the langauge to be bulletproof.

Considering the second example in your script, “exit is called in case of errors”: What is stopping the interpreter from storing the iterator of the current “for” loop in the top-level frame object? Then the iterator would be referenced by the exception traceback, and prevent garbage collection of its itercm() instance. Hypothetically:

__traceback__ → tb_frame → “for” iterator → itercm() instance

Also, I would tend to put this sort of function in “itertools”, since generators are not context managers by design.
History
Date User Action Args
2015-09-06 22:13:10martin.pantersetrecipients: + martin.panter, rhettinger, ncoghlan, pitrou, ezio.melotti, serhiy.storchaka
2015-09-06 22:13:10martin.pantersetmessageid: <1441577590.9.0.317537102647.issue25014@psf.upfronthosting.co.za>
2015-09-06 22:13:10martin.panterlinkissue25014 messages
2015-09-06 22:13:10martin.pantercreate