I have a page that submits data to this cgi script, this script then calls another executable. The issue is that this executable takes a very long time to run and as a result, it causes the cgi script to halt until finished. I'm trying to find a way to run it in the background. I'm coding in python on a linux machine. The issue that I'm running into is that when the script ends (the parent process is killed), the child process is also terminated by the init (in accordance with the linux spec). I googled around a little, and I came across this thread: Calling an external command in Python
I then tried the following in my code:
print <html code>
pid = subprocess.Popen([sys.executable, '/path/to/executable.py '+arg1],
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
...
retval = pid.wait()
#For debugging purposes:
print str(retval) + "<br/>"
print </html code>
This is giving me a retval of '2' which I'm sure means something wrong (because i'm not seeing the right output) I tried some other methods but it either runs the script and takes a while to load (Meaning that it's running in the foreground), or it just fails to run the script all together.
Ideas? Thank you. Oh, btw, I'm using python 2.6