【发布时间】:2021-02-17 18:34:20
【问题描述】:
代码:
execs = ['C:\\Users\\XYZ\\PycharmProjects\\Task1\\dist\\multiof1.exe',
'C:\\Users\\XYZ\\PycharmProjects\\Task2\\dist\\multiof2.exe',
'C:\\Users\\XYZ\\PycharmProjects\\Task3\\dist\\multiof3.exe',
'C:\\Users\\XYZ\\PycharmProjects\\failedprocess\\dist\\multiof4.exe'
]
print('Parent Process id : ', os.getpid())
process = [subprocess.Popen(exe) for exe in execs]
for proc in process:
proc.wait()
print('Child Process id : ', proc.pid)
if proc.poll() is not None:
if proc.returncode == 0:
print(proc.pid, 'Exited')
elif proc.returncode > 0:
print('Failed:', proc.pid)
在上面,.exe 的单子 .exe 将失败,我需要从父进程重新启动失败的 .exe。
我知道,上面的代码不是一个正确的实现,但是我用谷歌搜索没有找到合适的解决方案。
任何支持都将帮助我了解有关子流程的更多信息。
【问题讨论】:
-
我会为每个处理轮询状态并在失败时重新启动新的
subprocess.Popen()的进程编写一个包装类。 -
@AKX 是否有代码?
-
SO 不是代码编写服务,您应该可以自己编写这样的类。一般来说,“如果可能的话,用代码”意味着一次咨询演出,但因为这只花了 3 分钟......
-
@AKX 我是这项技术的新手,正在努力学习。我用谷歌搜索但没有找到合适或合适的解决方案,那是我的要求。所以我在 SO 中发帖寻求帮助。
标签: python-3.x subprocess exe