[mod_python] multiple processing of the same python script by the handler

David Sfiligoi webmaster at world-vr.com
Sun Mar 29 22:15:31 EDT 2009

Hi Graham,

Yes I agree defining my logger outside the mod python handler was a bad idea.  
Using the req.log_error works of course.  Obviously if I wanted integrate 
this into all the other apps that revolve around those logs, i'd have to 
write a converter or change each apps which parses the log data.

I'd like to understand this a bit better, perhaps I have the wrong basic idea 
on how the python handler works in overall, but if I install the log handler 
in the handler function and delete the log objects before ending, shouldn't 
that take care of the multiple logging issue?  

Or are you saying that each piece of code that should not produce multiple 
entries of the same thing should really be inside a module so I can let 
import_module() take care of it?

Im seeing the same 'multiplicity' issue when I open a socket while in handler 
function. This is really what trigger the question.



On Sunday 29 March 2009 05:45:01 am Graham Dumpleton wrote:
> If you change a mod_python handler script, it will be automatically
> reloaded. This would be a problem in your code as you installed a log
> handler each time it is loaded into the same process. Having multiple
> instances of the log handler installed would result in the same
> information possibly being logged multiple times.
> I would suggest you add inside your handler script:
>   req.log_error("I have been called")
> If that appears twice in the Apache error log file then I would be
> concerned, otherwise I would say the problem is with your use of the
> logging module.
> Also read about import_module() in:
>   http://www.modpython.org/live/current/doc-html/pyapi-apmeth.html
> as it explains a bit about module reloading and the way to preserve
> global data or avoid stuff which performs additive operations each
> time it is loaded.
> Graham

More information about the Mod_python mailing list