Python and FastCGI

MRAB python at mrabarnett.plus.com
Wed Dec 30 22:03:31 EST 2009


Steffen Ebermann wrote:
> Hi,
> 
> this might be a little off topic (could be any other language) 
> but I'm trying to set up Python to use FastCGI instead of plain CGI.
> 
> The basic setup is no problem but every tutorial (including Python's 
> 'HOWTO Use Python in the web') ends with some basic dispatch file and 
> that's it. I guess I should know how to go about from there, but,
> well I don't.
> 
> I guess I could put an execfile('index.py') into the dispatcher and
> then rewrite my code for FastCGI (i.e. replace every print with
> req.write() for jonpy), but that doesn't seem right to me.
> 
> Is there a better solution or do I misunderstand something entirely?
> I would be glad if someone could point me in the right direction.
> 
> Thanks in advance.
> 
Well, you don't have to replace every 'print', because it outputs by
calling sys.stdout.write(), so you could redirect the output by
replacing stdout with an instance that has a 'write' method, eg 'req'.
It might be as simple as doing:

     sys.stdout = req


It might be worth a try.



More information about the Python-list mailing list