This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gvanrossum
Recipients benhoyt, gvanrossum, martin.panter, serhiy.storchaka, vstinner
Date 2016-01-12.00:40:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
It was a bit more subtle. I think like this:

def f():
    with some_lock:
        yield 0
        yield 1

def g():
    with another_lock:
        it = f()
        for i in it:

We determined that another_lock was freed *before* some_lock.  This is because the local variable 'it' keeps the generator object returned by f() alive until after the with-block in g() has released another_lock.

I think this does not strictly require f to be a generator -- it's any kind of closable resource that only gets closed by its destructor.

The solution is to add a try/finally that calls it.close() before leaving the with-block in g().

Hope this helps.
Date User Action Args
2016-01-12 00:40:11gvanrossumsetrecipients: + gvanrossum, vstinner, benhoyt, martin.panter, serhiy.storchaka
2016-01-12 00:40:11gvanrossumsetmessageid: <>
2016-01-12 00:40:11gvanrossumlinkissue25994 messages
2016-01-12 00:40:11gvanrossumcreate