Message73052
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"! |
|
Date |
User |
Action |
Args |
2008-09-11 19:04:14 | dangyogi | set | recipients:
+ dangyogi |
2008-09-11 19:04:14 | dangyogi | set | messageid: <1221159854.86.0.0250666743089.issue3842@psf.upfronthosting.co.za> |
2008-09-11 19:03:14 | dangyogi | link | issue3842 messages |
2008-09-11 19:03:14 | dangyogi | create | |
|