diff --git a/Doc/library/os.rst b/Doc/library/os.rst index df01963e54a5e6..087a01d2d9efc1 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -4872,8 +4872,10 @@ operating system. .. function:: sched_getaffinity(pid, /) - Return the set of CPUs the process with PID *pid* (or the current process - if zero) is restricted to. + Return the set of CPUs the process with PID *pid* is restricted to. + + If *pid* is zero, return the set of CPUs the calling thread of the current + process is restricted to. .. _os-path: @@ -4914,12 +4916,12 @@ Miscellaneous System Information .. function:: cpu_count() - Return the number of CPUs in the system. Returns ``None`` if undetermined. - - 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))`` + Return the number of logical CPUs in the system. Returns ``None`` if + undetermined. + This number is not equivalent to the number of logical CPUs the current + process can use. ``len(os.sched_getaffinity(0))`` gets the number of logical + CPUs the calling thread of the current process is restricted to .. versionadded:: 3.4 diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index e643d8e5a4ce63..e4956b55a07e0a 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -1205,6 +1205,7 @@ def test_sched_getaffinity(self): @requires_sched_affinity def test_sched_setaffinity(self): mask = posix.sched_getaffinity(0) + self.addCleanup(posix.sched_setaffinity, 0, list(mask)) if len(mask) > 1: # Empty masks are forbidden mask.pop()