469,927 Members | 1,871 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

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 2253
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Kurt B. Kaiser | last post: by
2 posts views Thread by Simon Fletcher | last post: by
11 posts views Thread by Wentink | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
12 posts views Thread by adamurbas | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.