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

Armin Rigo armin.rigo at gmail.com
Tue Oct 18 04:01:51 EDT 2016


Hi,

On 17 October 2016 at 10:08, Nathaniel Smith <njs at pobox.com> wrote:
> thought I'd send around a draft to see what you think. (E.g., would
> this be something that makes your life easier?)

As a general rule, PyPy's GC behavior is similar to CPython's if we
tweak the program to start a chain of references at a self-referential
object.  So for example, consider that the outermost loop of a program
takes the objects like the async generators, and stores them inside
such an object:

    class A:
         def __init__(self, ref):
              self.ref = ref
              self.myself = self

and then immediately forget that A instance.  Then both this A
instance and everything it refers to is kept alive until the next
cyclic GC occurs.  PyPy just always exhibits that behavior instead of
only when you start with reference cycles.

So the real issue should not be "how to so something that will make
PyPy happy", or not only---it should be "how to do something that will
make CPython happy even in case of reference cycles".  If you don't,
then arguably CPython is slightly broken.

Yes, anything that can reduce file descriptor leaks in Python sounds good to me.


A bientôt,

Armin.


More information about the pypy-dev mailing list