Both os
and multiprocessing
modules define a cpu_count
function.
os.cpu_count
is documented as follows:
Return the number of CPUs in the system. Returns None if undetermined.
and multiprocessing.cpu_count
's documentation says:
Return the number of CPUs in the system. May raise NotImplementedError. See also os.cpu_count()
On my machine, they both return the same result:
>>> import os
>>> import multiprocessing as mp
>>> os.cpu_count()
8
>>> mp.cpu_count()
8
I would have thought that multiprocessing.cpu_count
would be a mere reference to os.cpu_count
, but it is not:
>>> os.cpu_count is mp.cpu_count
False
So what is the difference between them? Am I guaranteed that they'll always return the same result?
Moreover, if I want to specify a number of processes to create for multiprocessing.Pool
, should I use os
or multiprocessing
's function?