[Python-Dev] Why doesn't module finalization delete names as expected?

Antoine Pitrou solipsis at pitrou.net
Wed Feb 1 11:38:49 EST 2017


On Wed, 1 Feb 2017 03:23:02 -0500
Philippe Proulx <eeppeliteloop at gmail.com> wrote:
> 
> 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?

When do you expect module finalization to happen?  Your module is
recorded in sys.modules so, unless you explicitly remove it from there,
module finalization will only happen at interpreter shutdown.

(and this question is more appropriate for the python-list, anyway)

Regards

Antoine.



More information about the Python-Dev mailing list