[New-bugs-announce] [issue3842] can't run close through itertools.chain on inner generator
report at bugs.python.org
Thu Sep 11 21:04:14 CEST 2008
New submission from Bruce Frederiksen <dangyogi at gmail.com>:
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):
... # do stuff yielding values
... # clean up
>>> c = chain.from_iterable(map(gen, (1,2,3)))
>>> # 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:
>>> # generator finalized by "with closing"!
components: Extension Modules
title: can't run close through itertools.chain on inner generator
type: feature request
versions: Python 3.0
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce