Python CGI - outputting to textarea

Jeremy Bowers jerf at jerf.org
Mon Oct 11 23:36:51 CEST 2004


On Mon, 11 Oct 2004 14:18:26 -0700, LarsenMTL wrote:

> I have a long running python cgi which in the end returns a link to a
> pdf file. While it runs it generates a log that uses stdout right into
> the html.  I use the sys.stdout.flush() to make this log output
> relatively realtime.
> 
> The log, however, has grown too long.  I wish to output it instead
> into a textarea.  I thought I could just use the textarea tags before
> the output starts.  This works, but my output is no longer "real time"
> even with the flush (it waits till I close the textarea tag to display
> it).  Anyone know a method how I can make it write to the textarea as
> it goes?

You're fighting HTTP and HTML, which just aren't designed for this sort of
thing. Even your "relatively realtime" former implementation is an
accident; at any time any browser could choose to do more buffering and
un-real-time your log.

You're not likely to get more out of the solution than you already have.
Either trim the log, or, if it is getting long because it has to do more
that takes more time, tell the user their request has been accepted, and
email them when it is done. This is a common solution to this problem.

If you want to get crazy, fire the process off somehow, and create a way
for it to give status reports, and use client-side Javascript, with
XMLHTTPRequest, to read off the status periodically. This can in theory be
made cross-browser but I have no idea how true that is.



More information about the Python-list mailing list