'How to launch a Python function as an external program in a detached process?
I have a main program, in Python, which needs to launch Python submodules as processes. Until now I used "multiprocessing" and everything worked perfectly.
Now I have a new constraint which is to be able to kill the main program while leaving the child processes active.
With "multiprocessing", leaving the main program destroys the objects, and thus my created child processes.
So I switched to an implementation with "subprocess.Popen":
mySubProcess1 = subprocess.Popen(["python", "mySubMudule1.py", "myArg1"],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False)
This method works perfectly, my processes stay alive even when I quit the main program. On the other hand, I find it inelegant to have to recall "python".
Do you see another method without "subprocess.Popen(["python", ..."?
Thanks in advance, Seb
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
