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

Original file line numberDiff line numberDiff line change

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

1220412204

{

1220512205

int ncpu = 0;

1220612206

#ifdef MS_WINDOWS

12207-

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

12208-

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

12209-

HINSTANCE hKernel32;

12210-

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

12211-

Py_BEGIN_ALLOW_THREADS

12212-

hKernel32 = GetModuleHandleW(L"KERNEL32");

12213-

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

12214-

"GetMaximumProcessorCount");

12215-

Py_END_ALLOW_THREADS

12216-

if (_GetMaximumProcessorCount != NULL) {

12217-

ncpu = _GetMaximumProcessorCount(ALL_PROCESSOR_GROUPS);

12218-

}

12219-

else {

12220-

SYSTEM_INFO sysinfo;

12221-

GetSystemInfo(&sysinfo);

12222-

ncpu = sysinfo.dwNumberOfProcessors;

12223-

}

12207+

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

12208+

DWORD WINAPI GetActiveProcessorCount(WORD group);

12209+

ncpu = GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);

1222412210

#elif defined(__hpux)

1222512211

ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL);

1222612212

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