[issue33166] os.cpu_count() returns wrong number of processors on specific systems

Giampaolo Rodola' report at bugs.python.org
Wed Mar 28 10:53:13 EDT 2018


Giampaolo Rodola' <g.rodola at gmail.com> added the comment:

By re-reading
https://bugs.python.org/issue30581 and
https://github.com/giampaolo/psutil/issues/771#issuecomment-264457333 I now remember why I haven't fixed this issue in psutil yet: because the whole thing (MS APIs and doc basically) is confusing.

GetMaximumProcessorCount (now used by os.cpu_count()) returns "the maximum number of logical processors that a processor group or the system CAN have", not the actual number. That would explain why in OP's case os.cpu_count() returns 128 instead of 40.

As per https://bugs.python.org/issue30581#msg295255 dwNumberOfProcessors wasn't good because it doesn't take multiple processor groups into account (hence the number may be too small) and GetLogicalProcessorInformationEx may be the way to go. This is based on the assumption that os.cpu_count() should report the number of CPUs in the system (including the non-usable ones, like in case of process groups).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33166>
_______________________________________


More information about the Python-bugs-list mailing list