在Python中从父函数启动进程
我想知道我的进程是否已从启动此进程的函数停止工作在Python中从父函数启动进程,python,parent-child,python-multiprocessing,Python,Parent Child,Python Multiprocessing,我想知道我的进程是否已从启动此进程的函数停止工作 from multiprocessing import Process def parent_function(): i = 0 while True: #some code processing if i == 0: #start this process only first time temp = Process(target=process_function)
from multiprocessing import Process
def parent_function():
i = 0
while True:
#some code processing
if i == 0: #start this process only first time
temp = Process(target=process_function)
temp.start()
def process_function():
While True:
#some code waiting or processing
如果process\u function()
myparent\u function
中发生异常,则该函数不知道。如何从parent\u function()
重新启动该进程函数,并不断检查process\u function()
是否正在运行。您可以使用is\u alive()
方法检查子进程是否已终止。它返回True
或False
。在您的父函数()中可能是这样的:
您是否多次调用父函数以启动多个进程?否,父函数只调用一次,但父函数中有一个不确定的循环。只要这个循环还在运行,我就希望进程函数也在运行。实际上,我之前也是这样做的。无论如何,谢谢你的回答。
if not temp.is_alive():
# restart the process