[mod_python] Force reload?

Roman Roelofsen r.roelofsen at tuxed.de
Wed Feb 2 22:45:48 EST 2005

> Argh!  I wish that mod_python would check all loaded modules for changes
> as a flat rule, not as a tree...  because currently it will only reload
> something if I touch the handler, because the reload code sees that the
> handler hasn't changed and does not bother checking the modules that the
> handler uses for changes.  Might as well not even use mod_python.import()
> at all.
> Anyway, is there an option I can use to force the reload of the handler
> module each and every time a request is made?  I am only needing this for
> debugging purposes, so I don't mind something that is a bit kludgey.
> Thank you!  And please fix the import issue!

If you are using a unix-box, the easiest way would be to "touch" the handler 
file. Try adding this line at the top of the handler() function in the 
handler file. But I didn´t tested this and it is really quick and dirty. 

os.system("touch " + __file__)

On my system the handler calls this method on each request:

def reload():
    for k, v in sys.modules.items():
        if v:
            try: path = v.__file__
            except: continue            
            userpath = os.path.dirname(__file__)
            if path.startswith(userpath):
                del sys.modules[k]

This will force to reload all of my "custom" modules (nothing 
below /usr/lib/python). My handler is saved in the toplevel htdocs directory. 
This will slow down the whole request, so you should only use it in 

Hope it helps!

Best regards,


mail: r.roelofsen at tuxed.de

More information about the Mod_python mailing list