[mod_python] Auto-reload

Graham Dumpleton grahamd at dscpl.com.au
Fri Feb 4 21:33:59 EST 2005


On 05/02/2005, at 1:45 AM, Shawn Harrison wrote:

> Graham,
>
> Let's suppose I have the following four modules a.py, b.py, c.py, and 
> util.py in a folder in sys.path, and in httpd.conf I have 
> "PythonHandler a" for a given url space. If I make changes in a.py, 
> b.py or c.py, these changes are immediately visible in the browser.

As mentioned in my original email, it only works because the 
loading/reloading
of the module is done from inside every function, which can just get 
messy after a
while.

What most people are used to in Python is loading modules at global 
scope within a
module. Ie.,

   # c.py

   ...

   # b.py

   import c

   # a.py

   import b

Obviously, use this way isn't going to work, but the first thing people 
will try and
which would be preferable, is to replace the "import" where it is with:

   c = apache.import_module("c")

Ie., still at global scope in module.

This however doesn't work, as determination of whether sub import needs 
to be reload
is only done at import time of the parent module and not per request.

Thus, yes the way you have done it will work in the way you have used 
it, that is, in
every method, but use it at global scope as above and it doesn't and is 
not different
to how the mod_python module loader works.

Just think now of what you have to do if util.py had 40 methods and 
required other
sub modules imports. Every method that uses a sub module, has to load 
it. As I said
it gets messy and this shouldn't have to be the case. With Vampire's 
module loader
you can still do it at global scope (once) and it will work.

Graham






More information about the Mod_python mailing list