[pypy-dev] RFC: draft idea for making for loops automatically close iterators

Steven D'Aprano steve at pearwood.info
Fri Oct 21 19:13:52 EDT 2016


On Fri, Oct 21, 2016 at 10:13:45PM +0800, hubo wrote:

> Well I'm really shocked to find out what I thought was a "automatic 
> close" is really the ref-couting GC of CPython, means that a lot of my 
> code breaks in PyPy... 

But does it really?

If you've run your code in PyPy, and it obviously, clearly breaks, then 
why are you so shocked? You should have already known this. (Unless this 
is your first time running your code under PyPy.)

But if your code runs under PyPy, with no crashes, no exceptions, no 
failures caused by running out of file descriptors... then you can't 
really say your code is broken. What does it matter if your application 
doesn't close the files until exit, if you only open three files and the 
application never runs for more than two seconds?

I'd like to get a good idea of how often this is an actual problem, 
causing scripts and applications to fail when run in PyPy. Actual 
failures, not just wasting a file descriptor or three.



> I'm wondering since a ref-counting GC implemention is not possible for 
> PyPy, is it possible to hack on the for loop to make it "try to" 
> collect the generator? That may really save a lot of lives.

Saving lives? That's a bit of an exaggeration, isn't it?

There is a big discussion going on over on the Python-Ideas mailing 
list, and exaggerated, over-the-top responses aren't going to help this 
proposal's case. Already people have said this issue is only a problem 
for PyPy, so it's PyPy's problem to fix.



-- 
Steve


More information about the pypy-dev mailing list