Message3466
There is an incompatibility with CPython 2.5 w.r.t. to caling close on
iterator generators. Please consider the following code:
-----------
def gen3(n):
try:
for x in range(n):
print "gen3 for x, before for y, x:", x
for y in range(x+1):
print "gen3 for y, y:", y
yield y
print "gen3 for x, after for y, x:", x
finally:
print "gen3 finally"
def test3():
try:
generated = gen3(3)
for x in generated:
print "test3 for x, x:", x
break
generated.close()
finally:
print "test3 finally"
----
The output of CPython is:
gen3 for x, before for y, x: 0
gen3 for y, y: 0
test3 for x, x: 0
gen3 finally
test3 finally
The output of Jython is:
gen3 for x, before for y, x: 0
gen3 for y, y: 0
test3 for x, x: 0
test3 finally
It seems that closing the iterator generator does not run the finally
clause of gen3. |
|
Date |
User |
Action |
Args |
2008-09-01 06:55:20 | egonw_ | set | recipients:
+ egonw_ |
2008-09-01 06:55:20 | egonw_ | set | messageid: <1220252120.73.0.187257237517.issue1117@psf.upfronthosting.co.za> |
2008-09-01 06:55:20 | egonw_ | link | issue1117 messages |
2008-09-01 06:55:20 | egonw_ | create | |
|