Guido van Rossum added the comment:
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:
raise
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.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue25994>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com