I want to initiate a process from my python script main.py
. Specifically, I want to run the below command:
`nohup python ./myfile.py &`
and the file myfile.py
should continue running, even after the main.py
script exits.
I also wish to get the pid
of the new process.
I tried:
os.spawnl*
os.exec*
subprocess.Popen
and all are terminating the myfile.py
when the main.py
script exits.
Update: Can I use os.startfile
with xdg-open
? Is it the right approach?
Example
a = subprocess.Popen([sys.executable, "nohup /usr/bin/python25 /long_process.py &"],\
stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
print a.pid
If I check ps aux | grep long_process
, there is no process running.
long_process.py which keeps on printing some text: no exit.
Am I doing anything wrong here?