英文:
prevent AssertionError: daemonic processes are not allowed to have children
问题
I am running stuff using Pool
/multiprocessing
.
Whenever I call Pool again (nested) within one of the child processes of the main process, this error is raised?
prevent multiprocessing gives AssertionError: daemonic processes are not allowed to have children
Is there a way to detect if code is running already part of a Pool
, to be able to prevent this error?
英文:
I am running stuff using Pool
/multiprocessing
.
Whenever I call Pool again (nested) within one of the child processes of the main process, this error is raised?
prevent multiprocessing gives AssertionError: daemonic processes are not allowed to have children
Is there a way to detect if code is running already part of a Pool
, to be able to prevent this error?
答案1
得分: 1
可以获取当前进程实例并检查它是否为守护进程:
from multiprocessing import process
print(f"当前进程是否为守护进程: {process.current_process().daemon}")
输出:
当前进程是否为守护进程: False
在进程池内,该 .daemon
属性将为 True
。
英文:
Yes, you can get the current process instance and check whether it is daemonic or not:
from multiprocessing import process
print(f"is current process daemonic: {process.current_process().daemon}")
Output:
is current process daemonic: False
Inside a pool, that .daemon
property will be True
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论