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

2017-07-19 Thread Jakub Stasiak
Changes by Jakub Stasiak : -- nosy: +jstasiak ___ Python tracker ___ ___

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

2017-03-31 Thread Nathaniel Smith
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?

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

2016-11-14 Thread Nick Coghlan
Nick Coghlan added the comment: Oops, I forgot to mention one other potential cost-minimisation strategy for a `co_cleanuptab` field: only populate it with setup/cleanup opcode pairs that include a yield, yield from, or await operation between them. The potential benefit I can see to *not*

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

2016-11-14 Thread Nick Coghlan
Nick Coghlan added the comment: Martin raises an interesting point - the cases where ResourceWarning is likely to be appropriate are going to be those where the frame has been suspended inside a with statement or a try/finally statement. However, we don't currently track those at runtime or

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

2016-11-14 Thread Martin Panter
Martin Panter added the comment: BTW my understanding is that currently, if the garbage collector deletes a generator, it effectively calls its close() method. When close() is called, it throws GeneratorExit into the suspended generator. This is meant to cause all the “with” and “try”

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

2016-11-13 Thread Martin Panter
Martin Panter added the comment: Perhaps I shouldn’t have mentioned “del gen”. That was meant to represent the garbage collector running and calling gen.__del__() or equivalent. Basically what I was trying to say is I think there will be two classes of generators: 1. Simple generators just

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

2016-11-13 Thread STINNER Victor
STINNER Victor added the comment: > del gen # Like deleting a plain iterator; no ResourceWarning expected Hum, wait, I'm not sure that I got the whole point of this issue. If the generator uses "with obj:", "del gen" will not call obj.__exit__(). Do you consider that "del gen" is better to

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

2016-11-13 Thread Martin Panter
Martin Panter added the comment: This would be hard to get right, but maybe not impossible. If the frame is suspended, and will do special handling of GeneratorExit, a ResourceWarning would be nice in most cases. But if the frame will not catch any exception, there should be no

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

2016-11-07 Thread Nick Coghlan
Nick Coghlan added the comment: As Victor suggests, the reason I ended the issue title with a question mark is because I'm worried that doing this by default is likely to be too noisy to be useful. It's worth trying out though, even if it ends up being something we have to hide behind a -X

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

2016-11-07 Thread STINNER Victor
STINNER Victor added the comment: To take a decision, I would suggest to implement the warning, run the Python test suite, and run the test suite of a few applications like Twisted and Django, to see how much code needs to be modified. Well, let's say that my code consumes a generator but emits

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

2016-11-06 Thread Nathaniel Smith
Nathaniel Smith added the comment: +1 to the change for generators. This is actually in the PEP 533 draft: https://www.python.org/dev/peps/pep-0533/#modifications-to-basic-iterator-types For coroutines, doesn't this overlap with the existing "coroutine not awaited" warning? --

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

2016-11-06 Thread Nick Coghlan
New submission from Nick Coghlan: There have been a few discussions recently regarding the fact that generator and coroutine cleanup can suppress ResourceWarnings from other components. For example: def mygen(fname): with open(fname) as f: yield from f