[issue28629] Emit ResourceWarning when implicitly terminating a suspended frame?

Nathaniel Smith report at bugs.python.org
Fri Mar 31 22:10:10 EDT 2017


Nathaniel Smith added the comment:

It does make sense to skip emitting a warning if there's no try or with block active.

Don't we already have the ability to check for this, though, without any extensions to the frame or code objects? That's what the public PyGen_NeedsFinalizing does, right? It's implemented as a for loop over the frame's block stack, which in most cases should be extremely small, so the performance cost of running this from generator.__del__ seems likely to be minimal.

(I think currently the implementation is not *quite* correct if there's a 'yield from' active – in most cases it won't much matter because if A is yielding from B and A is collected, then B will probably be collected a moment later and have its own __del__ called. But this is not *quite* the same as what should happen, which is that collecting A should immediately call B.close(), which in principle might do something arbitrarily different than B.__del__. But adding a check for whether a 'yield from' is active would be pretty trivial.)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28629>
_______________________________________


More information about the Python-bugs-list mailing list