[mod_python] Multiple returns to client

Mike Looijmans nlv11281 at natlab.research.philips.com
Wed Sep 6 03:24:57 EDT 2006

Your output is buffered in multiple stages. In most cases, you can call 
"req.flush()" to send data to the client. This will usually work, unless 
you have a module or a filter installed that collects output until the 
final stage.

For example, this pattern shows how to send output from a slow query 
back to the user, so that he can see the results as they come back. By 
calling req.flush() at smart points, we make sure there's some feedback 
quite efficiently.

c.execute("SELECT name,date FROM persons")
while 1:
    data = c.fetchmany()
    if not data:
    for row in data:
        req.write("<tr><td>%s</td><td>%s</td></tr>" % row)

Mike Looijmans
Philips Natlab / Topic Automation

Ethan Toan Ton wrote:
> I was wondering if anyone knew of a way to return multiple times to a
> client using a Mod-Python event handler.  Using the req.write() method
> does nothing until the actual return statement sends all the data in one
> message back to the client.  So before you get to the actual return
> statement, can you output back to them more than once?

More information about the Mod_python mailing list