Closed
Description
Feature or enhancement
os.cpu_count() returns the total number of CPUs that the current machine has. On Unix, sched_setaffinity() can reduce the number of CPU "usable" by a process. Currently, os.cpu_count() docstring contains a recipe how to get the number of usable CPUs:
>>> import os; help(os.cpu_count)
cpu_count()
Return the number of CPUs in the system; return None if indeterminable.
This number is not equivalent to the number of CPUs the current process can
use. The number of usable CPUs can be obtained with
``len(os.sched_getaffinity(0))``
I propose to add an affinity optional keyword-only parameter to os.cpu_count() which would return len(os.sched_getaffinity(0))
.st
UPDATE: Rename usable parameter to affinity.
Linked PRs
- gh-109649: Add affinity parameter to os.cpu_count() #109652
- gh-109649: Add os.process_cpu_count() function #109907
- gh-109649: Use os.process_cpu_count() #110165
- [3.12] gh-109649: Enhance os.cpu_count() documentation #110169
- [3.11] [3.12] gh-109649: Enhance os.cpu_count() documentation (GH-110169) #110226
- gh-109649: Fix test_os.test_process_cpu_count_affinity() #111689