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
<https://docs.python.org/3/reference/datamodel.html#object.__del__> 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/

Reply via email to