Keep a python script running after browser window closed

S

sophie_newbie

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!
 
M

Mike Driscoll

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
 
S

sophie_newbie

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.
 
S

sjdevnull

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

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.
 

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

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top