Using python 3.8.8 on a windows box, how to determine the maximum number of processes that can be run per CPU core? I followed some previously asked related questions like 1,2,3,4.
Now the python docs on this subject suggest to use len(os.sched_getaffinity(0))
. However, when I try in code, it returns an error,
import os
print(len(os.sched_getaffinity(0)))
AttributeError: module 'os' has no attribute 'sched_getaffinity'
Then I try another code snippet to identify the available functions,
import os
print(dir(os))
and it gives me a list of functions wherein sched_getaffinity()
is not available.
My environment is:
The number of processes a CPU core can run simultaneously is equal to the number of threads per CPU core. And to get the number of threads per CPU core in python you can do something like this:
import psutil
total_threads = psutil.cpu_count()/psutil.cpu_count(logical=False)
print('You can run {} processes per CPU core simultaneously'.format(total_threads))
To check different processors your script can run on you can use:
print(psutil.Process().cpu_affinity())