If the warning text tells about the delayed execution -- I'm +1. -1 for something like "just don't use __del__, it is dangerous".
On Wed, Jan 1, 2020, 21:51 Gregory P. Smith <g...@krypto.org> wrote: > > > On Wed, Jan 1, 2020 at 6:40 AM Andrew Svetlov <andrew.svet...@gmail.com> > wrote: > >> __del__ is very useful not for interpreter shutdown but as a regular >> destructor in object's lifecycle. >> > > The reason we should warn people against ever implementing __del__ is that > people rarely actually understand object lifecycle. Its presence > guarantees delayed garbage collection and that its code will code execute > in a context way outside of normal control flow that all other methods are > invoked from. > > -gps > > >> >> Action on the shutdown is another beast. >> Personally, I prefer to do all finalization works by explicit calls >> instead. >> >> On Wed, Jan 1, 2020 at 2:39 AM Yonatan Zunger <zun...@humu.com> wrote: >> > >> > Hey everyone, >> > >> > I just encountered yet another reason to beware of __del__: when it's >> called during interpreter shutdown, for reasons which are kind of obvious >> in retrospect, if it calls notify() on a threading.Condition, the waiting >> thread may or may not ever actually receive it, and so if it does that and >> then tries to join() the thread the interpreter may hang in a hard-to-debug >> way. >> > >> > This isn't something that can reasonably be fixed, and (like in most >> cases involving __del__) there's a very simple fix of using >> weakref.finalize instead. My question for the dev list: How would people >> feel about changing the documentation for the method to more bluntly warn >> people against using it, and refer them to weakref.finalize and/or >> atexit.register as an alternative? The text already has an undertone of >> "lasciate ogni speranza, voi ch'entrate" but it may be helpful to be more >> explicit to avoid people getting caught in unexpected pitfalls. >> > >> > Yonatan >> > _______________________________________________ >> > 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/AAZQBWD6PHC4PVNCCPX4A2745SS7B3LS/ >> > Code of Conduct: http://python.org/psf/codeofconduct/ >> >> >> >> -- >> Thanks, >> Andrew Svetlov >> _______________________________________________ >> 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/57CDW4NIYEQ3JEVX2JVCJDA5TXTC5MBR/ >> Code of Conduct: http://python.org/psf/codeofconduct/ >> >
_______________________________________________ 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/NFGVEU53S37ZQZ2JEUFQIDYHQ6USR6DG/ Code of Conduct: http://python.org/psf/codeofconduct/