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

Keith Palmer Jr. keith at uglyslug.com
Sat Dec 2 23:28:08 EST 2006


Ahhh, excellent. I could definitely push for mod_python 3.3 when it is 
released and get it installed. Glad to hear it works correctly in the 
new version, this is a bit of a pain right now. :-)

And thanks for the code example for exec, I'll give it a try.

Liking Python more and more by the moment. I may already be a convert 
from the dark side (PHP, *gasp!*)

  - Keith


Graham Dumpleton wrote:
> 
> 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