mirror of
https://github.com/python/cpython.git
synced 2025-09-27 18:59:43 +00:00
bpo-30581: Windows: os.cpu_count() returns wrong number of processors (#2934)
* Fixes #30581 by adding a path to use newer GetMaximumProcessorCount API on Windows calls to os.cpu_count() * Add NEWS.d entry for bpo-30581, os.cpu_count on Windows. * Tweak NEWS entry
This commit is contained in:
parent
390eadd6d0
commit
c67bae0478
2 changed files with 18 additions and 3 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
os.cpu_count() now returns the correct number of processors on Windows
|
||||||
|
when the number of logical processors is greater than 64.
|
|
@ -11174,9 +11174,22 @@ os_cpu_count_impl(PyObject *module)
|
||||||
{
|
{
|
||||||
int ncpu = 0;
|
int ncpu = 0;
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
SYSTEM_INFO sysinfo;
|
/* Vista is supported and the GetMaximumProcessorCount API is Win7+
|
||||||
GetSystemInfo(&sysinfo);
|
Need to fallback to Vista behavior if this call isn't present */
|
||||||
ncpu = sysinfo.dwNumberOfProcessors;
|
HINSTANCE hKernel32;
|
||||||
|
hKernel32 = GetModuleHandleW(L"KERNEL32");
|
||||||
|
|
||||||
|
static DWORD(CALLBACK *_GetMaximumProcessorCount)(WORD) = NULL;
|
||||||
|
*(FARPROC*)&_GetMaximumProcessorCount = GetProcAddress(hKernel32,
|
||||||
|
"GetMaximumProcessorCount");
|
||||||
|
if (_GetMaximumProcessorCount != NULL) {
|
||||||
|
ncpu = _GetMaximumProcessorCount(ALL_PROCESSOR_GROUPS);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SYSTEM_INFO sysinfo;
|
||||||
|
GetSystemInfo(&sysinfo);
|
||||||
|
ncpu = sysinfo.dwNumberOfProcessors;
|
||||||
|
}
|
||||||
#elif defined(__hpux)
|
#elif defined(__hpux)
|
||||||
ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL);
|
ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL);
|
||||||
#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
|
#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue