Message3466

Author egonw_
Recipients egonw_
Date 2008-09-01.06:55:19
SpamBayes Score 3.3331937e-06
Marked as misclassified No
Message-id <1220252120.73.0.187257237517.issue1117@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2008-09-01 06:55:20egonw_setrecipients: + egonw_
2008-09-01 06:55:20egonw_setmessageid: <1220252120.73.0.187257237517.issue1117@psf.upfronthosting.co.za>
2008-09-01 06:55:20egonw_linkissue1117 messages
2008-09-01 06:55:20egonw_create