防止 AssertionError: 守护进程不允许有子进程

huangapple go评论72阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月24日 18:36:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76322597.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定