[Zope] Dynamic script loading

Dieter Maurer dieter@handshake.de
Wed, 9 Apr 2003 20:57:53 +0200


Jan Ma=1B-B=B9ka wrote at 2003-4-9 10:40 +0200:=1B-A
 > This is quite a gotcha! :-)
 > Try:
 >=20
 > import mymodule
 > #NOW IT'S LOADED
 > del ( mymodule )
 > #HERE IT SHOULD UNLOAD

This is *very* unlikely.

  First of all, there is a reference in "sys.modules".

  Then, when "mymodules" defines functions or methods, they
  reference "mymodule" and prevent unloading.

You can try:

    mymodule.__dict__.clear() # this clears the module
    import sys; del sys.modules['mymodule']
    del mymodule

When there are no longer any instances of classes defined
in "mymodule", it may unload...


Dieter