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

Original file line number Diff line number Diff line change
@@ -12176,23 +12176,9 @@ os_cpu_count_impl(PyObject *module)
12176 12176 {
12177 12177 int ncpu = 0;
12178 12178 #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);
12196 12182 #elif defined(__hpux)
12197 12183 ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL);
12198 12184 #elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)