[mod_python] module not reloading?

Michael C. Neel neel at mediapulse.com
Fri Sep 26 16:30:50 EST 2003


Hmm, without seeing any code, I'm out of ideas.  Here is the (python
2.2.2) docs on reload(), with all it's gotcha's you need to avoid...

reload(module) 
Re-parse and re-initialize an already imported module. The argument must
be a module object, so it must have been successfully imported before.
This is useful if you have edited the module source file using an
external editor and want to try out the new version without leaving the
Python interpreter. The return value is the module object (the same as
the module argument). 
There are a number of caveats: 

If a module is syntactically correct but its initialization fails, the
first import statement for it does not bind its name locally, but does
store a (partially initialized) module object in sys.modules. To reload
the module you must first import it again (this will bind the name to
the partially initialized module object) before you can reload() it. 

When a module is reloaded, its dictionary (containing the module's
global variables) is retained. Redefinitions of names will override the
old definitions, so this is generally not a problem. If the new version
of a module does not define a name that was defined by the old version,
the old definition remains. This feature can be used to the module's
advantage if it maintains a global table or cache of objects -- with a
try statement it can test for the table's presence and skip its
initialization if desired. 

It is legal though generally not very useful to reload built-in or
dynamically loaded modules, except for sys, __main__ and __builtin__. In
many cases, however, extension modules are not designed to be
initialized more than once, and may fail in arbitrary ways when
reloaded. 

If a module imports objects from another module using from ... import
..., calling reload() for the other module does not redefine the objects
imported from it -- one way around this is to re-execute the from
statement, another is to use import and qualified names (module.name)
instead. 

If a module instantiates instances of a class, reloading the module that
defines the class does not affect the method definitions of the
instances -- they continue to use the old class definition. The same is
true for derived classes. 



> -----Original Message-----
> From: Michael S. Fischer [mailto:michael at dynamine.net] 
> Sent: Friday, September 26, 2003 4:20 PM
> To: Michael C. Neel
> Cc: Seung Chan Lim; mod_python at modpython.org
> Subject: Re: [mod_python] module not reloading?
> 
> 
> Actually, my problem is that the main module reloads, but my called 
> modules don't, even if I call reload() explicitly.
> 
> --Michael
> 



More information about the Mod_python mailing list