[Python-Dev] Marking GC details as CPython-only
Xavier Morel
python-dev at masklinn.net
Wed Feb 13 20:09:28 CET 2013
On 2013-02-13, at 19:48 , Maciej Fijalkowski wrote:
> Hi
>
> I've tried (and failed) to find what GC details (especially finalizer
> semantics) are CPython only and which ones are not. The best I could
> find was the documentation of __del__ here:
> http://docs.python.org/2/reference/datamodel.html
>
> Things were pypy differs:
>
> * finalizers in pypy will be called only once, even if the object is
> resurrected. I'm not sure if this is detail or we're just plain
> incompatible.
>
> * pypy breaks cycles and runs finalizers in random order (but
> topologically correct), hence gc.garbage is always empty. I *think*
> this part is really just an implementation detail
>
> * we're discussing right now about running multiple finalizers. We
> want to run them in order, but if there is a link a -> b and a becomes
> unreachable, we want to reserve the right to call finalizer a then
> finalizer b, even if a.__del__ resurrects a. What do you think?
>
> Overall, the __del__ is baaad.
>
> Cheers,
> fijal
There may be one more, although I'm not sure whether it's a GC artifact
or something completely unspecified: if a context manager is part of a
suspended stack (because it's in a generator) when the program
terminates, cpython will run __exit__ but pypy will not
--
# -*- encoding: utf-8 -*-
class C(object):
def __enter__(self):
print ("entering")
def __exit__(self, *args):
print ("exiting")
def gen():
with C():
yield
r = gen()
next(r)
--
$ python2 test.py
entering
exiting
$ python3 test.py
entering
exiting
$ pypy test.py
entering
$
--
More information about the Python-Dev
mailing list