问题
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