473,545 Members | 1,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CGI and long running job

Hello,
I am using python and CGI to initiate a long running simulation (up to
5h long) on a remote machine. The main idea is that I use a form, enter
the parameters and a CGI scripts start the simulation using these
parameters. The structure of the script is:

1. Read paremeters
2. Display some information
3. Start the simulation

For step 3 I use either os.system or os.popen(2). The problem is that
the web server does not send the information of step 2 back to the
browser, unless step 3 is completed. The browser simply waits for a
response, without displaying anything. How can I just read the params,
display the info I want, start the simulation and then terminate either
the script or at least the connection to the browser without having to
wait for the simulation to finish?

I am using activestate python 2.4, Apache and WinXP.

Thanks a lot for your help.

Dec 3 '05 #1
5 2476

me**********@gm ail.com wrote:
Hello,
I am using python and CGI to initiate a long running simulation (up to
5h long) on a remote machine. The main idea is that I use a form, enter
the parameters and a CGI scripts start the simulation using these
parameters. The structure of the script is:

1. Read paremeters
2. Display some information
3. Start the simulation

For step 3 I use either os.system or os.popen(2). The problem is that
the web server does not send the information of step 2 back to the
browser, unless step 3 is completed. The browser simply waits for a
response, without displaying anything. How can I just read the params,
display the info I want, start the simulation and then terminate either
the script or at least the connection to the browser without having to
wait for the simulation to finish?

I am using activestate python 2.4, Apache and WinXP.

Thanks a lot for your help.


Maybe you could use 'os.spawn' variants with the P_NOWAIT parameter...
(not sure of the syntax here, it's in the doc)
Good luck!

Dec 3 '05 #2
jm*********@gma il.com wrote:
me**********@gm ail.com wrote:
Hello,
I am using python and CGI to initiate a long running simulation (up to
5h long) on a remote machine. The main idea is that I use a form, enter
the parameters and a CGI scripts start the simulation using these
parameters. The structure of the script is:

1. Read paremeters
2. Display some information
3. Start the simulation

For step 3 I use either os.system or os.popen(2). The problem is that
the web server does not send the information of step 2 back to the
browser, unless step 3 is completed. The browser simply waits for a
response, without displaying anything. How can I just read the params,
display the info I want, start the simulation and then terminate either
the script or at least the connection to the browser without having to
wait for the simulation to finish?

I am using activestate python 2.4, Apache and WinXP.

Thanks a lot for your help.


Maybe you could use 'os.spawn' variants with the P_NOWAIT parameter...
(not sure of the syntax here, it's in the doc)
Good luck!


Thanks for answering. I tried that but it didn't work. Nothing is sent
back to the browser until the spawned process has ended. This is true
even if the spawn command (or any other similar command) is the last
statement of the script.

Is there some way to send back to the browser whatever info I need,
close the connection and then continue executing the commands I need,
using the same script?

Dec 3 '05 #3
Le die Fri, 02 Dec 2005 20:35:52 -0800, merry.sailor ha scribite:
For step 3 I use either os.system or os.popen(2). The problem is that
the web server does not send the information of step 2 back to the
browser, unless step 3 is completed. The browser simply waits for a
response, without displaying anything. How can I just read the params,
display the info I want, start the simulation and then terminate either
the script or at least the connection to the browser without having to
wait for the simulation to finish?


Sounds weird. What if you connect to the webserver via telnet? Do you get
any output?
you could try to call sys.stdout.flus h() in the CGI, but I never had the
need to do that.
Maybe it's just a browser's problem?
--
Saluti,
Mardy
http://interlingua.altervista.org

Dec 3 '05 #4
Hello Mardy,
thanks a lot for your help. I found the problem. Your suggestion made
me look into some things I haven't thought before :-). I don't know if
it is a browser/server/mine fault. The problem was that I was sending
text/plain and a txt file. I soon as I started sending back to the
browser text/html and an html file, I started getting the things I
wanted on screen, but the browser still waited for the script to
terminate, which resulted in a timeout. After I also closed stdout,
everything worked fine. The strange thing is that I tried closing
stdout with the plain text before, but it didn't work.

Dec 3 '05 #5
me**********@gm ail.com wrote:
Hello,
I am using python and CGI to initiate a long running simulation (up to
5h long) on a remote machine. The main idea is that I use a form, enter
the parameters and a CGI scripts start the simulation using these
parameters. The structure of the script is:

1. Read paremeters
2. Display some information
3. Start the simulation

For step 3 I use either os.system or os.popen(2). The problem is that
the web server does not send the information of step 2 back to the
browser, unless step 3 is completed. The browser simply waits for a
response, without displaying anything. How can I just read the params,
display the info I want, start the simulation and then terminate either
the script or at least the connection to the browser without having to
wait for the simulation to finish?


You need to close stdout, which closes the socket and allows the browser to
finish. This is what I use:

# We flush stdout, fork, then close stdout. This closes the HTTP socket,
# allowing the browser to continue while we munge with sendmail.

sys.stdout.flus h()
if os.fork(): return
fw = open('/dev/null','w')
os.dup2(fw.file no(),1)
os.dup2(fw.file no(),2)
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Dec 4 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3156
by: Bob Murdoch | last post by:
I'm developing an intranet application using W2k server and IE5.5 - 6.x clients. I've got one particular function that calls a stored procedure to update a number of records, depending on user input. The problem we have run into is that this procedure can take a few minutes to complete in certain circumstances, and of course IIS times out. ...
1
1475
by: Richard A. DeVenezia | last post by:
I have a function that will update a divs innerHTML with the result of a long running loop. I would like to update the div prior to running the loop so the person knows it is doing something. i.e. function doit () { mydiv.innerHTML = 'working...'; .... long running loop generates html in variable s mydiv.innerHTML = s }
29
5772
by: pb648174 | last post by:
I have a very long transaction that runs on the same database that other users need to use for existing data. I don't care if they see data from the transaction before it is done and am only using the transaction because I need a way to roll it back if any errors happen during the transaction. Unfortunately all tables affected in the long...
1
2303
by: Dan | last post by:
Good Day, I have a Windows Service that is responsible for processing somes files. One method of the service invokes another method which may take a while to complete its work. Something like this pulbic class A { public void ProcessFile()
5
3364
by: PontiMax | last post by:
Hi, when I press the OK button of my dialog box a long-running task is initiated. Therefore I would like to make visible a div section right after clicking the button where a user-friendly message is displayed... How can this be done? Can I make the section visible via server-side code? Via Response.Write()? Any examples would be...
1
6003
by: Anonieko | last post by:
Query: How to display progress bar for long running page Answer: Yet another solution. REFERENCE: http://www.eggheadcafe.com/articles/20050108.asp My only regret is that when click the browser back button, it loads the progress bar again. Any solution to this?
1
3464
by: Aaron West | last post by:
Try this script to see what queries are taking over a second. To get some real output, you need a long-running query. Here's one (estimated to take over an hour): PRINT GETDATE() select count_big(*) from sys.objects s1, sys.objects s2, sys.objects s3, sys.objects s4, sys.objects s5 PRINT GETDATE()
14
23123
by: lmttag | last post by:
Hello. We're developing an ASP.NET 2.0 (C#) application and we're trying to AJAX-enable it. We're having problem with a page not showing the page while a long-running process is executing. So, we're looking for a way to display the page with a "please wait..." message while the process is running, and then, when the process is done, update...
4
2843
by: commander_coder | last post by:
Hello, I write a lot of CGI scripts, in Python of course. Now I need to convert some to long-running processes. I'm having trouble finding resources about the best practices to do that. I've found a lot of email discussions that say something like, "You need to educate yourself about the differences when you have long- running...
2
1620
by: =?Utf-8?B?QWxwaGFwYWdl?= | last post by:
Hello, I have a class MyWorker. Each time I create a new instance of MyWorker, I queue it to the ThreadPool. So, 1 MyWorker object is pooled and belongs to its thread (there can't have 2 MyWorker in 1 thread from the ThreadPool). When MyWorker is initialized or instanciate, I use an asynchronous delegate to execute a long running process ...
0
7457
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7802
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7746
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5962
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5320
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4941
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1010
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
693
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.