From: Charles-François Natali Date: Mon, 13 Jul 2015 20:01:39 +0000 (+0100) Subject: Issue #23530: Improve os.cpu_count() description. X-Git-Tag: v3.6.0a1~1971 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dc87e4b88551f64cb4053d8ea72dffc0c3675413;p=python Issue #23530: Improve os.cpu_count() description. Patch by Julian Taylor. --- diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index 8703f8f5ec..e74430df7e 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -869,8 +869,13 @@ Miscellaneous .. function:: cpu_count() - Return the number of CPUs in the system. May raise - :exc:`NotImplementedError`. + Return the number of CPUs in the system. + + 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))`` + + May raise :exc:`NotImplementedError`. .. seealso:: :func:`os.cpu_count` diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 16e5019f86..0acb8a570f 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -3596,6 +3596,11 @@ Miscellaneous System Information 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))`` + + .. versionadded:: 3.4 diff --git a/Misc/ACKS b/Misc/ACKS index 8a007ea9dc..e4ba783953 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1385,6 +1385,7 @@ William Tanksley Christian Tanzer Steven Taschuk Amy Taylor +Julian Taylor Monty Taylor Anatoly Techtonik Gustavo Temple diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index ec8c526c0a..23d74a3e0e 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -5760,7 +5760,7 @@ os.sched_getaffinity pid: pid_t / -Return the affinity of the process identified by pid. +Return the affinity of the process identified by pid (or the current process if zero). The affinity is returned as a set of CPU identifiers. [clinic start generated code]*/ @@ -11201,7 +11201,9 @@ get_terminal_size(PyObject *self, PyObject *args) /*[clinic input] os.cpu_count -Return the number of CPUs in the system; return None if indeterminable. +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))`` [clinic start generated code]*/ static PyObject *