[mod_python] avoiding apache restarts to reimport modules and refresh global cache

Graham Dumpleton grahamd at dscpl.com.au
Thu Sep 15 12:43:19 EDT 2005

On 16/09/2005, at 12:24 AM, Huzaifa Tapal wrote:

> I have been using my python based web application framework, slither, 
> which was recently upgraded to be a mod_python handler for more than 6 
> months now for various applications at my company.  One dillema I see 
> with the persistent environment with mod_python is that everytime I 
> update code in production, i have to restart apache so that my library 
> modules can be reloaded as well as any caching I am using.
> I am using apache.import_module() to import any page modules in my 
> applications and those get reimported at every change since they have 
> the autoreload turned on.  I also know that Vampire has a pretty good 
> module importing system then that provided by apache.import_module().  
> I was wondering if it would be a good idea overwrite the 
> __builtin__.import() method with that of Vampire's import_module or 
> apache.import_module() so that the checks of "mtime" are done and the 
> reloads happen automatically.
> Is there another better way of reloading all my library modules and 
> refreshing the cache?

One shouldn't override '__builtin__.import()'. There are however other
ways of achieving the same thing. See:


Vampire does support a means of enabling an import hook in compliance
with PEP 302 which means that the "import" statement when used in
certain cases will underneath actually use Vampire's equivalent of the
'apache.import_module()' method. The feature isn't on by default though.

There has been a bit of discussion on the developers list for mod_python
around improving the module importing system, including the possibility
of using such an import hook. Making any changes though has been
deferred to mod_python 3.3.


More information about the Mod_python mailing list