I'm writing a daemon process in python3.4 that manages 2-3 other external processes. I try to avoid the GIL by just compartmentalizing the work they do. These other processes are temporary in nature. So what I need:
Start a process from within a python interpreter and immediately detach it from the one that started it. I want them to be fully isolated without sharing stdout, stderr, stdin or other resources. I do not want to wait for the process exit, return code, stdout, stderr or provide data through stdin.
According to the docs, it's now recommended to subprocess. This is what I use now:
subprocess.Popen(["python3.4", daemonfile], env=env)
It works, but:
- when the process is started, stdout and stderr are printed on the same console the main daemon was started. I want them to be fully detached.
- with 'shell=True', the python interpreter enters 'interpreter mode' instead.
- subprocess.Popen was recommend in favour of os.spawn*** calls
What is the best way to start a complete separate process (technically, not even a child?) and have it fully detached from the parent, such that they don't share resources?
shell=Truetogether with a list argument. Compare:sh -c 'python a.py'vs.sh -c 'python' a.py(you don't want the latter). - jfsstdin,stdout,stderrtoDEVNULLin your case. - jfs