Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[3.12] gh-109649: Enhance os.cpu_count() documentation #110169

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

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5141,8 +5141,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:
Expand Down Expand Up @@ -5183,12 +5185,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

Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down