Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get number of workers from process Pool in python multiprocessing module

Tags:

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

like image 543
gc5 Avatar asked Dec 03 '13 14:12

gc5


People also ask

How do you find number of employees?

For example, say you're open 5 days per week: 3 days you have 100 Workers and 2 days you have 50 Workers. You can report the average of 80 Workers (3 days * 100 Workers +2 days * 50 workers / 5 days open = 80 Workers on Main Shift).

What is the default number of worker processes created in a Python process pool?

processes is the number of worker processes to use. If processes is None then the number returned by os. cpu_count() is used. For example, if we had 4 physical CPU cores with hyperthreading, this would mean we would have 8 logical CPU cores and this would be the default number of workers in the process pool.

How do processes pools work in multiprocessing?

Pool allows multiple jobs per process, which may make it easier to parallel your program. If you have a numbers jobs to run in parallel, you can make a Pool with number of processes the same number of as CPU cores and after that pass the list of the numbers jobs to pool. map.

What is pool in multiprocessing Python?

The Pool class in multiprocessing can handle an enormous number of processes. It allows you to run multiple jobs per process (due to its ability to queue the jobs). The memory is allocated only to the executing processes, unlike the Process class, which allocates memory to all the processes.


1 Answers

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 
like image 180
falsetru Avatar answered Oct 02 '22 08:10

falsetru