Skip to content

Commit b370b73

Browse files
committed
pythongh-109649: Enhance os.cpu_count() documentation
* Doc: Specify that os.cpu_count() counts *logicial* CPUs. * Doc: Specify that os.sched_getaffinity(0) is related to the calling thread. * Fix test_posix.test_sched_getaffinity(): restore the old CPU mask when the test completes!
1 parent 8882b30 commit b370b73

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

Doc/library/os.rst

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5141,8 +5141,10 @@ operating system.
51415141

51425142
.. function:: sched_getaffinity(pid, /)
51435143

5144-
Return the set of CPUs the process with PID *pid* (or the current process
5145-
if zero) is restricted to.
5144+
Return the set of CPUs the process with PID *pid* is restricted to.
5145+
5146+
If *pid* is zero, return the set of CPUs the calling thread of the current
5147+
process is restricted to.
51465148

51475149

51485150
.. _os-path:
@@ -5183,12 +5185,8 @@ Miscellaneous System Information
51835185

51845186
.. function:: cpu_count()
51855187

5186-
Return the number of CPUs in the system. Returns ``None`` if undetermined.
5187-
5188-
This number is not equivalent to the number of CPUs the current process can
5189-
use. The number of usable CPUs can be obtained with
5190-
``len(os.sched_getaffinity(0))``
5191-
5188+
Return the number of logical CPUs in the system. Returns ``None`` if
5189+
undetermined.
51925190

51935191
.. versionadded:: 3.4
51945192

Lib/test/test_posix.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,7 @@ def test_sched_getaffinity(self):
12051205
@requires_sched_affinity
12061206
def test_sched_setaffinity(self):
12071207
mask = posix.sched_getaffinity(0)
1208+
self.addCleanup(posix.sched_setaffinity, 0, list(mask))
12081209
if len(mask) > 1:
12091210
# Empty masks are forbidden
12101211
mask.pop()

0 commit comments

Comments
 (0)