I'm running into a problem using the subprocess module to open completely independent processes through Python. I need the process spawned by the python script to live on even if the python program dies. I've noticed that subprocess creates a child process and nohup is not keeping it alive. It needs to work both on Windows and Linux, so I'm not sure if os.fork will work.
The structure I am aiming for is a main program running at all times that calls other programs, and if the main program dies I want the spawned programs to live on.
Main program
import subprocess
import time
subprocess.Popen(["/usr/bin/python", "/home/jchoinski/Desktop/Sentinel1.1/programTest.py"], stdin=subprocess.PIPE, stdout=PIPE, stderr=PIPE)
while True:
time.sleep(1)
Spawned Program
import time
l = 1
while l < 100000:
l += 1
print(l)
time.sleep(1)
The process tree looks like this:
MainProgram
|_CalledProgram
and I want it to look like:
MainProgram
CalledProgram
Any ideas? Should I even use subprocess for this?