[mod_python] Multiple returns to client

Ethan Toan Ton ethanton at ethanton.com
Wed Sep 6 05:23:02 EDT 2006


Thanks for the help.  req.flush() works for sending out the data. 
Unfortunately, at the same time, my python program is making requests and
receiving data from other http sources at the same time.  When I run the
req.flush(), it outputs some of the incoming data as well.  Not sure why
that is happening.


> 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.
> ...
> req.write("<P>Results:</P><table><tr><th>Name</th><th>Date</th></tr>")
> req.flush()
> c=database.cursor()
> c.execute("SELECT name,date FROM persons")
> while 1:
>     data = c.fetchmany()
>     if not data:
>         break
>     for row in data:
>         req.write("<tr><td>%s</td><td>%s</td></tr>" % row)
>     req.flush()
> req.write("</table>")
> ...
> 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?
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python

More information about the Mod_python mailing list