Does Python cache the startup module?

Fredrik Lundh fredrik at pythonware.com
Mon Jan 7 15:22:47 EST 2008


Baz Walter wrote:

> Before changing the name 'mainwindow' to 'mainwidget' it reports:
> 
> Widgets left: 0    Max widgets: 2
> Widgets left: 0    Max widgets: 149 (full program)
> 
> Afterwards it reports:
> 
> Widgets left: 1    Max widgets: 2
> Widgets left: 146    Max widgets: 149 (full program)

So what you're concerned about is the lack of cleanup during interpreter 
shutdown, not a true leak (which would result in "Max widgets" growing 
towards infinity).

The problem here is that you're relying on Python's GC to remove things 
in a given order during shutdown, something that may or may not happen
depending on lots of things that you cannot control:

     http://www.python.org/doc/essays/cleanup/

(Note the repeated use of "In an order determined by the dictionary 
hashing of the names" in that article.)

The only way to get *predictable* shutdown behaviour in situations like 
this is to clean things up yourself.  But in this case, you might as 
well leave the cleanup to the OS.

</F>




More information about the Python-list mailing list