如何检查子进程是否仍在运行?

2024-09-24 00:24:57 发布

您现在位置:Python中文网/ 问答频道 /正文

出于安全原因,我需要再次检查子进程是否仍然有效。我是这样产生的:

NdeProc = Process(target=NodeRun, args=(NodeQ,))
NdeProc.start()

我真的只想在“NodeRun”还在运行的情况下检查我的主进程?我还没有在docu中找到任何东西,我想我可能需要做一个时间戳文件,在这个文件中我会不断更新子进程的时间戳,父进程可以检查它,但是我想知道somone是否能想出更好的方法?在

谢谢!在


Tags: 文件target进程时间情况args原因process
1条回答
网友
1楼 · 发布于 2024-09-24 00:24:57

使用^{}进行此操作:

if NdeProc.is_alive():
    ...
else:
    ...

根据文件:

Return whether the process is alive. Roughly, a process object is alive from the moment the start() method returns until the child process terminates.

相关问题 更多 >