dynamic modules

Michael Hudson mwh at python.net
Wed Dec 19 17:01:51 EST 2001


Chris Barker <chrishbarker at attbi.com> writes:

> Michael Hudson wrote:
> > Fernando Pérez <fperez528 at yahoo.com> writes:
> > > import plugin1 as p1
> > >
> > > ...
> > >
> > > del p1
> > > In the next gc pass it should get picked up.
> > 
> > This won't work; consider sys.modules.
> 
> while you can't delete an entire module, can you delete some of it's
> members? Example:
> 
> import plugin
> 
> # do stuff
> 
> del plugin.largedatastructure
> 
> If I did this, would the datastructure be deleted?

Depends if there are any other references to it.  They'll probably be
easier to find than all the references to modules though.

If this is an extension module, it very much depend on how the code in
the extension module accesses the data in "largedatastructure".

> If so, it would acomplish most of what the OP wanted. The module would
> still be there, but the large data structure wouldn't be. It also looks
> like a reload() would bring back the data, although I'm not sure how
> well that would work with a compiled module.

I think reload() is a no-op for compiled modules.


Cheers,
M.



More information about the Python-list mailing list