Module magic methods

G. David Kuhlman dkuhlman at netcom.com
Sun Jun 13 16:36:58 EDT 1999


Michael Hudson (mwh21 at cam.ac.uk) wrote:
> 
> You know that, in general, modules aren't unloaded, except at
> interpreter shutdown time? And then the execution state is so
> unpredictable you can't really do anything?
> 
> HTH
> Michael
> 

Witticisms by Dave: "Questions on comp.lang.python are like clothes
hangers in your closet. You try to pull out one, and twenty come
tangled to it."

Maybe, in general, modules aren't unloaded.  But what if I do:

    import mymodule
    #
    # Do some stuff with mymodule
    #
    mymodule = None

Won't reference counting cause the space taken up by mymodule to be
garbage collected?  I hope so, because, where I work, this is what
I'm going to tell them to do when they want to reclaim space in
long running programs.

[Pause for thought and experimentation with Python ... ]

Oops.  Wait a minute.  What if I create an instance on of class
defined in mymodule:

    anInstance = mymodule.MyClass()
    mymodule = None
    anInstance.show()

Something must stay around so that I can call the methods defined
MyClass.

[Pause for more heavy thinking in a light-weight brain ...]

OK, then what about after all the reference counts for instances of
mymodule go to zero?

    anInstance = None

  - Dave




More information about the Python-list mailing list