从 Python 中的父函数启动进程
Start Process From Parent Function in Python
我想知道我的进程是否已停止从启动此进程的函数运行
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_function()
中发生异常,我的 parent_function
不知道。如何从 parent_function()
重新启动该进程函数并继续检查 process_function()
是否为 运行。
您可以使用is_alive()
方法检查子进程是否终止。它 returns True
或 False
。在你的 parent_function()
:
中可能是这样的
if not temp.is_alive():
# restart the process
我想知道我的进程是否已停止从启动此进程的函数运行
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_function()
中发生异常,我的 parent_function
不知道。如何从 parent_function()
重新启动该进程函数并继续检查 process_function()
是否为 运行。
您可以使用is_alive()
方法检查子进程是否终止。它 returns True
或 False
。在你的 parent_function()
:
if not temp.is_alive():
# restart the process