看起来job=subprocess.Popen,job.pid没有给出正确的pid,而pid+1似乎可以工作
我检查了线程: Python subprocess.popen wrong pidpython - subprocess.Popen().pid return the pid of the parent script
但他们都没有回答我的问题
我的工作(据说‘PID+1’的成功率是99%,我还没有失败,但感觉到了可能性)代码如下:
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)
这是在后台运行外部软件。有没有更好的方法来获得正确的PID
如果它自己运行python代码,有没有更好的方法
我在使用time.sleep()时没有使用任何fork线程,这会使外部cfl3d软件休眠吗
如果通过Popen()执行的是python代码,这会使popend python休眠吗
非常感谢
目前没有回答
相关问题 更多 >
编程相关推荐