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

Original file line number Diff line number Diff line change
@@ -12204,23 +12204,9 @@ os_cpu_count_impl(PyObject *module)
12204 12204 {
12205 12205 int ncpu = 0;
12206 12206 #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);
12224 12210 #elif defined(__hpux)
12225 12211 ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL);
12226 12212 #elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)