求助 Python multiprocessing 守护进程为什么不允许有子进程?

2019-06-20 17:02:34 +08:00
 jibabi
本人代码如下:

import multiprocessing
import time

def process_a():
for _ in range(10):
print("process a")
time.sleep(1)

def process_b():
print("process b")
ps = []
for _ in range(3):
p = multiprocessing.Process(target=process_a)
p.daemon = True
p.start()
ps.append(p)
for i in ps:
i.join()

if __name__ == '__main__':
p = multiprocessing.Process(target=process_b)
p.daemon = True
p.start()
p.join()

运行报错:AssertionError: daemonic processes are not allowed to have children
想问一下 multiprocessing 是出于什么原因,决定守护进程不能再创建子进程?谢谢
4326 次点击
所在节点    Python
2 条回复
liuguichao
2019-07-03 09:42:03 +08:00
Note that a daemonic process is not allowed to create child processes. Otherwise a daemonic process would leave its children orphaned if it gets terminated when its parent process exits. Additionally, these are not Unix daemons or services, they are normal processes that will be terminated (and not joined) if non-daemonic processes have exited.
wuwukai007
2019-07-18 17:36:59 +08:00
设置环境变量 export PYTHONOPTIMIZE=1

ldconfig

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/575895

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX