]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-109649: Enhance os.cpu_count() documentation (#110169)
authorVictor Stinner <vstinner@python.org>
Mon, 2 Oct 2023 15:47:57 +0000 (17:47 +0200)
committerGitHub <noreply@github.com>
Mon, 2 Oct 2023 15:47:57 +0000 (17:47 +0200)
* gh-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!

* Restore removed text

Doc/library/os.rst
Lib/test/test_posix.py

index 4ffd520f9ecd8bffdb6b3a77d6f55116a836b1fe..0c36c244ab53dbe6f5e67d19f4b2f4dd13f91851 100644 (file)
@@ -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:
@@ -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
 
index 444f8abe4607b717c4749057a41c169ce6225dc2..9d72dba159c6bee537636bcbfa241f2dcde8eb4a 100644 (file)
@@ -1205,6 +1205,7 @@ class PosixTester(unittest.TestCase):
     @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()