Long cgi page

S

Simon Faulkner

I am writing a simple cgi app and I would like it to print the header
of an html page and "Running..." then print the results (which take
over a minute to calculate)

But...

None of the page displays until the program finishes.

Is there any way of flushing the first half of the page out before the
calculation starts?

Simon
 
B

bromden

None of the page displays until the program finishes.

it's because the http server "waits" till the cgi program finishes,
flushing stdout will not work
 
A

A.M. Kuchling

Is there any way of flushing the first half of the page out before the
calculation starts?

You're better off using a redirect. On the inital request, run the
calculation in a subprocess or a subthread and return a brief page that says
"Please wait...". This page should contain a <META HTTP-EQUIV="Refresh">
element that will reload the page in some suitable time span. On reloading,
the application should check if the computation is done and either return
the results or another "Please wait" page.

Quixote pseudocode:

def calc
HTML:
 (request):
    if not request.session.computation_in_progress():
        # Fork off subprocess
    elif request.session.computation_completed():  
        "Results:"
	...		  
    else:
        # Computation is in process
        "<html><head>"
	'<meta http-equiv="refresh" content="10; %s">' % request.get_url()
	'</head><body> ... </body></html>'

You'd have to write the computation_completed() and computation_in_progress()
methods.

--amk
 
D

Dave Benjamin

You're better off using a redirect. On the inital request, run the
calculation in a subprocess or a subthread and return a brief page that says
"Please wait...". This page should contain a <META HTTP-EQUIV="Refresh">
element that will reload the page in some suitable time span. On reloading,
the application should check if the computation is done and either return
the results or another "Please wait" page.

I don't know how to translate this to Quixote, but another way to do this
would be to use an HTTP refresh header, which has the additional advantage
that it's not strictly limited to HTML.

Just a thought,
Dave
 

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
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top