-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add usable_cpu_count() function #1122
Comments
|
Actually I'm confused: I now realize it should already be possible to get usable CPU count on Windows with |
On Linux the both ways return the number of currently enabled cpu cores. Also these files can be used to brign up/down cores and check their statuses. |
It's actually more complicated. cgroups can limit the amount of usable CPUs, see https://bugs.python.org/issue36054 |
Windows Containers use Job objects to limit the number of CPUs so to work inside a container would require querying this object |
Recently
os.cpu_count()
on Windows has been fixed in order to take process groups into account and return the number of all available CPUs:http://bugs.python.org/issue30581
The fix will be included in psutil too (#771) but that's another story.
This made me realize that psutil.cpu_count() does not return the number of usable CPUs, which could possibly represent a better default value for things like multiprocessing and process pools.
It is currently possible to retrieve this info on UNIX with
len(os.sched_getaffinity(0))
which takes CPU affinity and (I think) Linux cgroups into account, but it's not possible to do the same on Windows which is supposed to provide this value viaGetActiveProcessorCount()
API.The text was updated successfully, but these errors were encountered: