views:

60

answers:

1

I have a python CGI which runs some script in the background and shows the stdout in the html page. I run the script when the user clicks some button in the page.

My problem is when the script starts running the page becomes busy and the user can't use the other client side features in the page.

What I want is: The script should run in background when the user clicks the button and should notify the CGI when run is complete. Then the CGI show should the stdout of the script run.

How can this be done?

+1  A: 

well, short answer: you can't.

medium answer: CGI sucks.

long answer: CGI works by running your script and returning whatever your script prints to the browser. If your script is still running, the browser will be waiting. If your script launches a background job and returns data to the browser, then the background job can't notify the CGI script because it is already done.

You must choose an alternate solution.

Save the results of the background job to a file, database, or some other persistent storage, and make the user request that data, using another link in your page, which runs a different code that retrieves the saved results and display them.

Another way is to use AJAX techniques in the browser. Write javascript code to do the request to the data in the background. So the browser can still be responsive with other page elements while the script is running.

nosklo
Thans nosklo. Is there a way I can make my CGI show a loading icon when it is executing the script instead of simply looking busy?
Cagey
@Cagey: That is normally done by using javascript to do the request (AJAX).
nosklo
Thanks for your help nosklo. That was very useful :)
Cagey