I want to create a child process which will run after the parent has finished.
I have tried:
subprocess.Popen(['myscript'])
exit()
The child is created, but the parent waits until the child has finished. Instead, I want to finish quickly and let the child do the hard work in the background. Any suggestions?
Some clarifications:
- it is running on Linux (Ububntu Server 14.04)
- python 2.7 preferably
- I don't want to communicate with the child in any way. The child is totally independent process.
I need the main process to finish quickly as it will be accessed from the web. It is meant to trigger another script. The result will be sent to email later on (by the child process). So, no need for the user to wait for the answer. Just quick "ok" and then the child starts.
EDIT: Okay. Now to be honest, even my example in this post works in the simplest case (just those 2 lines + script which sleeps for 10 seconds + writes a file => main finishes and I get a file in 10 seconds). The actual situation is somewhat more complicated.
There is one script, which iterates over a list of scripts which all have to be executed. This main script uses subprocess.Popen with communicate() (waits for the output). This calls my "main" script which I'm asking help here. This "main" does something and then wants to run a child in background. In that context, the "main" waits for the child.
I will try to make a short cleaned up code example.
subprocess.Popen(['myscript'], start_new_session=True)
– multivac