Python 守护进程不允许有子进程
我知道这是一个常见的问题,和类似的相关问题,但我想问一个适合我的场景的最佳方式,因为我现在还没有用过芹菜 我的服务场景将使用multi-processing.Process创建多个活动订单,在每个活动订单中,它仍然使用multi-processing.Process创建多个广告(活动和广告是1toM关系) 如你们所知,若我在活动和广告创建部分都设置了多进程,它将失败,“恶魔进程不允许有孩子”,我认为芹菜可能会遇到类似的问题,即使我现在还没有使用它 我的问题是,解决这类问题的一般方法是什么?我应该还是用芹菜,还是用其他方法来解决 非常感谢。一般良好解决办法 您应该使用消息队列来解耦 比如说,Python 守护进程不允许有子进程,python,multiprocessing,daemon,Python,Multiprocessing,Daemon,我知道这是一个常见的问题,和类似的相关问题,但我想问一个适合我的场景的最佳方式,因为我现在还没有用过芹菜 我的服务场景将使用multi-processing.Process创建多个活动订单,在每个活动订单中,它仍然使用multi-processing.Process创建多个广告(活动和广告是1toM关系) 如你们所知,若我在活动和广告创建部分都设置了多进程,它将失败,“恶魔进程不允许有孩子”,我认为芹菜可能会遇到类似的问题,即使我现在还没有使用它 我的问题是,解决这类问题的一般方法是什么?我应该
多广告任务
推送到队列_2rq
/芹菜
2.简单的解决方法
如果getAssertionError
,则改用thread
def run_in_subprocess(func, *args, **kwargs):
from multiprocessing import Process
thread = Process(target=func, args=args, kwargs=kwargs)
thread.daemon = True
thread.start()
return thread
def run_in_thread(func, *args, **kwargs):
from threading import Thread
thread = Thread(target=func, args=args, kwargs=kwargs)
thread.daemon = True
thread.start()
return thread
def run_task(config):
try:
run_in_subprocess(xxxx_task, config)
except AssertionError:
print('daemonic processes are not allowed to have children, use thread')
run_in_thread(xxxx_task, config)
我在一些演示应用程序中使用此代码,但我不建议在生产中使用