Get number of workers from process Pool in python multiprocessing module

做~自己de王妃 提交于 2020-12-02 05:30:24

问题


I am trying to figure a way to get the number of processes directly from an instance of multiprocessing.Pool class in Python.. Is there a way to do it?

The documentation doesn't show anything related.

Thanks


回答1:


You can use _processes attribute:

>>> import multiprocessing
>>> pool = multiprocessing.Pool()
>>> pool._processes
8

The return value is same for multiprocessing.cpu_count() unless you specified process count when creating Pool object.

>>> multiprocessing.cpu_count()
8


来源:https://stackoverflow.com/questions/20353956/get-number-of-workers-from-process-pool-in-python-multiprocessing-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!