On Sun, 05 Jan 2020 12:37:24 +1300
Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:
> On 5/01/20 11:41 am, Antoine Pitrou wrote:
> 
> > +1 for pointing to `weakref.finalize` as a better
> > alternative for things that may survive until interpreter shutdown.  
> 
> I'm not sure that weakref.finalize is much better. It can still be
> called at an arbitrary time from an arbitrary thread with the rest
> of the system in an unknown state, so it needs to be written very
> defensively to cope with that.

I didn't say otherwise.  The main thing going for `weakref.finalize` is
that it is called at the beginning of the interpreter shutdown while
__del__ may be called much later in the process.

> I don't think a blanket warning against using __del__ would be
> very helpful, because many of its pitfalls also apply to the
> suggested alternatives. This is an area where there's no
> substitute for an in-depth understanding of the issues.

I didn't suggest a blanket warning either.  I do believe there should
be a discussion, somewhere in the docs, of the various options
available for finalization and their respective pitfalls.

However, many (most?) Python developers know about __del__, while few
know about `weakref.finalize`, so it makes sense to add a pointer to
the latter in the docs for the former.

Regards

Antoine.

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/YEMIGOLDY4KZYG3KU2UEXWMS3G6G7BC4/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to