Hey, I just tried an experiment about sending content from WSGI
application that needs to wait for some time.

Basically for starting the response the status is "200 OK" and headers
[("Content-Type", "text/plain; encoding=utf-8")]

For the actual data I returned the calling of this function that
yields 7 kB of data every 10 seconds:


import time

def delayer():
    for i in range(10):
        yield ("At %s s\n"%i)*1024
        time.sleep(10)
    yield "Done!"


Of course this is an artificial example with no real-world touch, but
the point is that I will be making an application that sometimes will
need to fetch content from another web server, parse it, and then make
its output to the client. Most of the time it will use cached version
of the data, returning immediately, but periodically it should check
if the data on the other server is updated and for that it would be
nice to have it first output some text such as "Updating
information...", then fetch and process the data, and after that do
the rest of the output.

Now what I would have wanted the behavior be is that the first 7 kB
block of "At 0 s" would be sent immediately to the client, then after
10 seconds the second block would be sent, and so on. What actually
happens is any web browser waits for 100 seconds before there is *any
response* from the server, then gets the whole document.

I tried setting Content-Length explicitly in the headers, but that did
not have any effect as the actual output to client was encoded with
gzip and the real Content-Length header represented the compressed
size. Since PEP-0333 states that "WSGI servers, gateways, and
middleware must not delay the transmission of any block; they must
either fully transmit the block to the client, or guarantee that they
will continue transmission even while the application is producing its
next block." I trust that mod_wsgi itself conforms to this promise, so
my suspect turns to the gzip procedure causing the output to be
buffered instead of being sent to the client immediately when
available.

Now naturally the question is how I could force mod_wsgi/Apache to
send any output to the client immediately after available from the
WSGI application? Of course, if Content-Length is not supplied by the
application, chunked coding must be used since the final length of the
output cannot be known beforehand. So is there a way the application
itself could ask the server to use chunked transfer or do I need to
somehow modify my Apache configuration or .htaccess file.

Some technical data (more will be provided if asked):

Ubuntu 9.04 amd64 Server edition
Apache/2.2.11
mod_wsgi/3.2 (daemon mode)
Python/2.6.2

- Joonas Lehtolahti

P.S. I accidentally sent this first with wrong e-mail address and that
post has not appeared in the mailing list, so I assume it was rejected
because it was sent from e-mail not registered. In case it actually
was sent but is waiting in moderation, it can be discarded.

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/modwsgi?hl=en.

Reply via email to