[mod_python] How to stop reimporting modules

Barry Pearce barry.pearce at copyrightwitness.net
Sat Apr 9 13:36:04 EDT 2005


Hi Jim,

>> This is an interesting issue - I have my own handler but I have a 
>> problem where mod_python does NOT cause modules to be reloaded - 
>> despite having changed on the disk I would have expected the module to 
>> reload...but it stays the same until I restart the web server - 
>> perhaps there is something Im doing wrong!!
>>
>> I really dont want to restart the apache server to upgrade my software 
>> - it kills all current sessions and downloads....
>>
>> Any ideas?
> 
> 
> My impression is that the handler specified in the apache PythonHandler 
> directive does not get reloaded when changed. Of course I may be 
> completely off the mark here.

Ah. OK....thats why everything that it in turn imports also remains 
fixed in memory...its just a pain in the bum when I change something 
that the re-import does not take place.

> For my code, the PythonHandler cms.publisher is just a stub that does a 
> little pre-processing and then uses apache.import_module() to get my 
> real handler. It's apache.import_module that does the reloading magic, 
> and so I avoid restarting apache when my handler code changes. I figure 
> once my code has pretty much settled down, I can change the 
> PythonHandler to specify the real handler.

The issue comes during upgrade of live sites with many users with 
concurrent sessions and no 'quiet' period per say where a restart could 
be sensibly placed.

Interestingly I have been using a large number of python files and using 
the standard python import - however, if the top level module is not 
reimported it will never execute any of the other import statements.

Interesting...sorry im rambling...

Perhaps I need to re-evaluate my import strategy and call 
apache.import_module() instead of just relying on the python import...

Now I dont want it all checked on each request - but maybe I can write a 
handler that I can send a request to which re-evalutes all imported 
modules and then appropriately reloads them...

hmmm...?

any ideas?

Cheers,
Barry


More information about the Mod_python mailing list