Philippe Proulx <eeppelitel...@gmail.com> writes: > ... > It feels like `bread` is never deleted in the module initialization > situation, but I don't know why: the only reference to the Bread Python > object is this `bread` name in the module... what could prevent this > object's __del__() method to be called? It works when I call `del bread` > manually: I would expect that the module finalization does the exact > same thing?
I expect, you are speaking about "module finalization" as part of "process finalization", i.e. when the whole Python process terminates: a module is not "finalized" at the end of its code execution. Python's behaviour during process finalization is complex (and has changed over time). It may still be prone to surprises. Somewhere, there is a document describing in details how Python performs finalization. When I last read it (may have changed meanwhile), it told that first "_*" variables are unbound, then the module dict is cleared. -- https://mail.python.org/mailman/listinfo/python-list