[Web-SIG] Re: Regarding the WSGI draft

Ian Bicking ianb at colorstudy.com
Sat Aug 28 06:03:28 CEST 2004


Phillip J. Eby wrote:
> At 05:09 PM 8/27/04 -0500, Ian Bicking wrote:
> 
>> Though it can cause problems.  E.g., if instead of the cgi server 
>> passing sys.stdout.write, it passed:
>>
>> def write(s):
>>     sys.stdout.write(s)
>>
>> That would cause all sorts of problems.  Unless it used 
>> sys.__stdout__.write(s); I don't know if that would be a good or bad 
>> style.  That's what I did to work around my bug.
> 
> 
> There's another way...  make the dummy file object put in for sys.stdout 
> do this:
> 
>     def write(self,data):
>         sys.stdout = self.__oldstdout__
>         try:
>             self.wsgi_writefunc(data)
>         finally:
>             sys.stdout = self
> 
> Voila.  Now, even if the WSGI server is written to use stdout, it still 
> works.  The same trick can and should be used for stdin and stderr.

Hmm... possibly.  Another thought I had was to buffer all the output, 
then only return as an iterator (or with a single call to the server's 
write function) when the application has finished.  This way the only 
problem would be with server extensions, as no server code would 
normally be written while the script was running.  Hrm, though that has 
its own problems if the script needs to stream output.  Yours would be 
more general in that case.

-- 
Ian Bicking  /  ianb at colorstudy.com  / http://blog.ianbicking.org


More information about the Web-SIG mailing list