I'm using subprocess.Popen
to launch several processes.
The code is something like this:
while flag > 0:
flag = check_flag()
c = MyClass(num_process=10)
c.launch()
MyClass
if something like the following:
MyClass(object)
def __init__(self, num_process):
self.num_process = num_process
def launch(self):
if self.check_something() < 10:
for i in range(self.num_process):
self.launch_subprocess()
def launch_subprocess(self):
subprocess.Popen(["nohup",
"python",
"/home/mypythonfile.py"],
stdout=open('/dev/null', 'w'),
stderr=open('logfile.log', 'w'),
shell=False)
In most of the cases, the launched subprocess dies, sometimes in the middle of the run. In some cases, it completes.
However, if I use subprocess.Popen
directly in the while loop, the process continues and finished timely.
Could someone tell me how can I get the processes to run in the background by using subprocess in the way as I described above?