Looks like the job=subprocess.Popen, job.pid not giving the right PID, instead PID+1 seems to work
I checked the thread: Python subprocess.popen wrong pid python - subprocess.Popen().pid return the pid of the parent script
but none of them really answered my question.
my working (it is said the successful rate of ‘PID+1’ is 99%, I ddidn't fail yet, but felt the possibility) code is follows:
def Running(PID):
try:
os.kill(PID, 0)
except OSError:
return False
else:
return True
job=subprocess.Popen('cfl3d_seq<cfl3d.inp &', shell=True)
Runs.append(int(job.pid)+1)
print(int(job.pid)+1)
print(Runs)
time.sleep(10)
while len(Runs)>=TotalRun:
for run in Runs:
if Running(run)==False:
print('kill ', run)
Runs.remove(run)
time.sleep(60)
This is running a external software in the background. Is there any better clean way to get the right PID?
If it is running python code itself, is there any better way to do this?
I didn't use any fork thread when using time.sleep(), will this sleep the external cfl3d software?
if what executed through Popen() is python code, will this sleep the popened python?
Thank you very much!