[mod_python] Tutorials, FieldStorage and sys.py. A depressingsaga.

Mike Looijmans mike.looijmans at asml.com
Fri May 23 09:47:33 EST 2003


>You can easily force print statement to work in mod_python. Request
>object has method 'write' and it is only method that print statement
>calls on destination object. So you can replace sys.stdout with req.


Drawback is that there is only ONE sys.stdout per interpreter. So make very
sure that only ONE thread can write to sys.stdout...
cgihandler does this, and the result is that only one thread can be active.
With the worker mpm on apache, the python/cgi system will effectively become
single-threaded.

The other way around is much better: let all your handlers receive a file like
"output" object, and write to that object. When using CGI, you assign
sys.stdout, and in mod_python, you can use the request object. This allows
multithreading in mod_python, a must-have if you use any thread-based apache
MPM.

In fact, I let the CGI version of the handler create a Request-like object
(mimic) based on environ strings, which I pass to the mod_python based
scripts. This yields max performance on mod_python, and an unnoticable drop on
CGI based Python scripting (the overhead of starting a new interpreter process
is much, much bigger than the creation of the reqeust object).

Mike.




More information about the Mod_python mailing list