[Python-Dev] del is not called after creating a new reference (original) (raw)
Oleg Nesterov oleg at redhat.com
Tue Mar 21 14:22:23 EDT 2017
- Previous message (by thread): [Python-Dev] __del__ is not called after creating a new reference
- Next message (by thread): [Python-Dev] why _PyGen_Finalize(gen) propagates close() to _PyGen_yf() ?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 03/20, Nathaniel Smith wrote:
Modern CPython, and all extant versions of PyPy and Jython, guarantee that del is called at most once. MicroPython doesn't support user-defined del methods. It's fine if the text wants to leave that open, but the current phrasing is pretty misleading IMO. I also read it as saying that del would be called again if the object is collected again (which may or may not happen).
Yes, that is why I was confused. Just I could not believe nobody else noticed this "bug" so I decided to check the sources and yes, the code looks very clear.
But AFAICT there are actually zero implementations where this is true.
Probably this was mostly true until the commit 796564c2 ("Issue #18112: PEP 442 implementation (safe object finalization)."), python2 calls del again.
Probably worth a small edit :-)
Agreed. And it seems that not only me was confused, http://doc.pypy.org/en/latest/cpython_differences.html says:
There are a few extra implications from the difference in the GC. Most
notably, if an object has a __del__, the __del__ is never called more
than once in PyPy; but CPython will call the same __del__ several times
if the object is resurrected and dies again.
Thanks to all!
Oleg.
- Previous message (by thread): [Python-Dev] __del__ is not called after creating a new reference
- Next message (by thread): [Python-Dev] why _PyGen_Finalize(gen) propagates close() to _PyGen_yf() ?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]