bpo-33166: Change os.cpu_count to return active (real) processors (GH… · python/cpython@43ee0e2

Original file line numberDiff line numberDiff line change

@@ -12176,23 +12176,9 @@ os_cpu_count_impl(PyObject *module)

1217612176

{

1217712177

int ncpu = 0;

1217812178

#ifdef MS_WINDOWS

12179-

/* Vista is supported and the GetMaximumProcessorCount API is Win7+

12180-

Need to fallback to Vista behavior if this call isn't present */

12181-

HINSTANCE hKernel32;

12182-

static DWORD(CALLBACK *_GetMaximumProcessorCount)(WORD) = NULL;

12183-

Py_BEGIN_ALLOW_THREADS

12184-

hKernel32 = GetModuleHandleW(L"KERNEL32");

12185-

*(FARPROC*)&_GetMaximumProcessorCount = GetProcAddress(hKernel32,

12186-

"GetMaximumProcessorCount");

12187-

Py_END_ALLOW_THREADS

12188-

if (_GetMaximumProcessorCount != NULL) {

12189-

ncpu = _GetMaximumProcessorCount(ALL_PROCESSOR_GROUPS);

12190-

}

12191-

else {

12192-

SYSTEM_INFO sysinfo;

12193-

GetSystemInfo(&sysinfo);

12194-

ncpu = sysinfo.dwNumberOfProcessors;

12195-

}

12179+

/* Declare prototype here to avoid pulling in all of the Win7 APIs in 3.8 */

12180+

DWORD WINAPI GetActiveProcessorCount(WORD group);

12181+

ncpu = GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);

1219612182

#elif defined(__hpux)

1219712183

ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL);

1219812184

#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)