473,490 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Keep a python script running after browser window closed

Hi,

I have a cgi script that performs a very long computation that can
take several hours to complete. Is there any smart way that I can keep
this script running until it is finished (after the user has closed
the browser) and email them with the results. The email bit isn't the
problem, I just don't know how to keep the code running in the
background. I'm sure there is a smart way to do this...

Thanks!
Mar 7 '08 #1
3 2413
On Mar 7, 10:28 am, sophie_newbie <paulgeele...@gmail.comwrote:
Hi,

I have a cgi script that performs a very long computation that can
take several hours to complete. Is there any smart way that I can keep
this script running until it is finished (after the user has closed
the browser) and email them with the results. The email bit isn't the
problem, I just don't know how to keep the code running in the
background. I'm sure there is a smart way to do this...

Thanks!
You might have your cgi script use the subprocess module to open a
second script that does the long-running process.

Mike
Mar 7 '08 #2
On Mar 7, 4:33 pm, Mike Driscoll <kyoso...@gmail.comwrote:
On Mar 7, 10:28 am, sophie_newbie <paulgeele...@gmail.comwrote:
Hi,
I have a cgi script that performs a very long computation that can
take several hours to complete. Is there any smart way that I can keep
this script running until it is finished (after the user has closed
the browser) and email them with the results. The email bit isn't the
problem, I just don't know how to keep the code running in the
background. I'm sure there is a smart way to do this...
Thanks!

You might have your cgi script use the subprocess module to open a
second script that does the long-running process.

Mike
Ya it looks like:

import subprocess

# spawn subprocess
subprocess.Popen(["python", "spawn.py"])

Should do this job, where spawn.py is the script to do the job.
Thanks.
Mar 10 '08 #3
On Mar 10, 1:42 pm, sophie_newbie <paulgeele...@gmail.comwrote:
On Mar 7, 4:33 pm, Mike Driscoll <kyoso...@gmail.comwrote:
On Mar 7, 10:28 am, sophie_newbie <paulgeele...@gmail.comwrote:
Hi,
I have a cgi script that performs a very long computation that can
take several hours to complete. Is there any smart way that I can keep
this script running until it is finished (after the user has closed
the browser) and email them with the results. The email bit isn't the
problem, I just don't know how to keep the code running in the
background. I'm sure there is a smart way to do this...
Thanks!
You might have your cgi script use the subprocess module to open a
second script that does the long-running process.
Mike

Ya it looks like:

import subprocess

# spawn subprocess
subprocess.Popen(["python", "spawn.py"])

Should do this job, where spawn.py is the script to do the job.
Thanks.
In real life, you probably want spawn.py to do a full daemonize. That
means fork/setsid/fork/chdir appropriately/deal with stdin/stdout/
umask, or however you set up a service on Windows.

Mar 10 '08 #4

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

Similar topics

6
2411
by: Sam | last post by:
Only 2 weeks messing around with it ( thanks to programs like SYNCHRONEX and BITORRENT ), and already trying to create windows ( the paths are just too long for me to want to type them ). After...
0
1866
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 241 open ( -6) / 2622 closed (+26) / 2863 total (+20) Bugs : 764 open ( +6) / 4453 closed (+38) / 5217 total (+44) RFE : 150 open...
4
2358
by: LarsenMTL | last post by:
Python Users: Based on previous suggestions from this group, I'm attempting to write a python CGI that takes input from an HTML form, invokes a second python script using this input, tells the...
2
9293
by: Simon Fletcher | last post by:
Hello there, I need a "Close Window" script ( onLoad.Close.Window() ), however i need the script so it don't come up with this annoying window: "This window is trying to close" window. Is...
11
2806
by: Wentink | last post by:
Does anybody have a simple script that let's me popup a picture from a thumbnail? The ones i found are all very very complicated and messy in the source... Thanks, Tintin
4
2240
by: Hal | last post by:
Can someone please tell me what is wrong with this script? <script language="JavaScript"> <!-- function HF_CloseAllChildren() { if (g_win1) != undefined { if ((g_win1) && !(g_win1.closed))...
0
1558
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 391 open ( +7) / 3028 closed (+12) / 3419 total (+19) Bugs : 906 open ( -3) / 5519 closed (+19) / 6425 total (+16) RFE : 207 open...
12
2980
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed...
1
5888
by: apurvaG | last post by:
Hi All, I wanted to know, can I check in action script whether the browser window which loads my swf file has been closed? Basically I wanted to call a action script function which will be...
0
7108
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,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7181
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...
0
5445
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,...
1
4875
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...
0
4565
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...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
272
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...

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.