[Web-SIG] Emulating req.write() in WSGI

Aaron Fransen aaron.fransen at gmail.com
Mon Jun 28 23:43:00 CEST 2010

On Mon, Jun 28, 2010 at 3:11 PM, P.J. Eby <pje at telecommunity.com> wrote:

> At 01:01 PM 6/28/2010 -0600, Aaron Fransen wrote:
>> One of the nice things about mod_python is the req.write() function.
>> Although I realize it's somewhat of an abuse to the http protocol, it's
>> handy being able to periodically update the client browser with a status
>> message for a long-running job.
>> So handy in fact that I have a number of applications that rely fairly
>> heavily on it as a means of keeping the client (person) happy instead of
>> just showing them the default "browser busy" notification.
>> There are a couple of workarounds, neither of which are ideal:
>> 1. Take them immediately to a secondary page, then submit the actual job
>> automatically on that second page.
>> 2. Instead of using HTTP POST, use an HTTP Request Object (ie. Ajax).
>> Both of them involve significantly more development effort than an
>> equivalent req.write().
>> Is there a way to emulate the periodic-write functionality in WSGI?
> Each string yielded (or passed to the write() callable returned by
> start_response) is supposed to be sent straight through to the client.
> As long as your WSGI stack is actually conformant to the protocol, that's
> all you need to do.
Using mod_wsgi on Apache doesn't seem to exhibit that behavior.

Experimentation with the write() functionality variously produces *only* the
helper text, or only the final result page, it doesn't incrementally update
the user. This behaviour appears to be dependent on the inclusion of the
Content-Length header field.

Yield command has not produced better results either, as it seems to produce
the yield output then, as far as what's presented to the browser, exit the
program completely (yet no errors in the log to speak of).

I'll experiment with yield some more to see if I can more sharply define
what's going on.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/web-sig/attachments/20100628/fab88f2f/attachment.html>

More information about the Web-SIG mailing list