I don't want to recommend atexit or weakref because they have their pitfall.
I think the context manager should be considered at first when people want to use __del__. On Wed, Jan 1, 2020 at 9:35 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/ -- Inada Naoki <songofaca...@gmail.com> _______________________________________________ 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/RSG6DHNG7ZTJCNYSAMVOFFQSD7HFSGKE/ Code of Conduct: http://python.org/psf/codeofconduct/