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 dangyogi
Recipients dangyogi
Date 2008-09-11.19:03:14
SpamBayes Score 1.1872602e-05
Marked as misclassified No
Message-id <1221159854.86.0.0250666743089.issue3842@psf.upfronthosting.co.za>
In-reply-to
Content
There is no way to get generators to clean up (run their 'finally'
clause) when used as an inner iterable to chain:

>>> def gen(n):
...     try:
...         # do stuff yielding values
...     finally:
...         # clean up
>>> c = chain.from_iterable(map(gen, (1,2,3)))
>>> next(c)
0
>>> # done with c, but can't clean up inner gen!

Could you add a 'close' method to itertools.chain that would call close
(if present) on both the inner and other iterable?  Then clean up could
be done as:

>>> with closing(chain.from_iterable(map(gen, (1,2,3)))) as c:
...    next(c)
>>> # generator finalized by "with closing"!
History
Date User Action Args
2008-09-11 19:04:14dangyogisetrecipients: + dangyogi
2008-09-11 19:04:14dangyogisetmessageid: <1221159854.86.0.0250666743089.issue3842@psf.upfronthosting.co.za>
2008-09-11 19:03:14dangyogilinkissue3842 messages
2008-09-11 19:03:14dangyogicreate