[mod_python] Force reload of all imported files on *every* request?

Graham Dumpleton grahamd at dscpl.com.au
Sat Dec 2 23:20:56 EST 2006


On 03/12/2006, at 2:57 PM, Keith Palmer Jr. wrote:
>
> Is there a way with mod_python to force it to reload all imported  
> files on every request?
>
> It's a development server but I *cannot* edit httpd.conf and most  
> other suggestions I've seen deal with restarting apache everytime I  
> edit a file... that is to say the least cludgy.

If you can't edit httpd.conf, then the answer is "No". The approach  
which requires
editing the httpd.conf file is to set:

   MaxRequestsPerChild 1

The only solution I can offer is to say that automatic module  
reloading works
properly in mod_python 3.3. That alas hasn't been released yet, but  
if I can
finish off some documentation it will hopefully will be relatively soon.

What version of mod_python are you currently using? Could you even get
them to upgrade the version of mod_python in a timely manner if 3.3 were
available or are you going to be stuck with an old version for a long  
time?

> Also, if I have a text block of code (reading it from the database)  
> with a class definition and a single import (urllib) can I use exec 
> () to declare that class and then use it? So I want to do this:
>
> code = "my code is here, this is a class definition and an from  
> urllib import urlopen statement"
> exec(code)
> myinst = MyClassName()

Yes. But using something like the following may be better as it then  
encapsulates
the result as a module.

   import imp
   module = imp.new_module('mymodulename')
   exec(code, module.__dict__)

   myinst = module.MyClassName()

You can then save away the module for later use as needs be.

Graham


More information about the Mod_python mailing list