New submission from Bruce Frederiksen <[EMAIL PROTECTED]>: 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"! ---------- components: Extension Modules messages: 73052 nosy: dangyogi severity: normal status: open title: can't run close through itertools.chain on inner generator type: feature request versions: Python 3.0 _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3842> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com