Why doesn't module finalization delete names as expected?

dieter dieter at handshake.de
Thu Feb 2 05:19:48 EST 2017


Philippe Proulx <eeppeliteloop at 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.




More information about the Python-list mailing list