Python CGI - outputting to textarea

L

LarsenMTL

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?

Thanks,

Mark
 
J

Jeremy Bowers

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.
 
M

Michael Foord

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?

Thanks,

Mark

Using javascript to read the data and insert it into the text box,
with a regular refresh sounds like the way forward. *OR* close a
textarea tag every few k of text and start a new box....

Regards,

Fuzzy

http://www.voidspace.org.uk/atlantibots/pythonutils.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,088
Members
47,684
Latest member
sparada

Latest Threads

Top