]> granicus.if.org Git - python/commitdiff
bpo-33166: Change os.cpu_count to return active (real) processors (GH-15949)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 11 Sep 2019 15:56:13 +0000 (08:56 -0700)
committerGitHub <noreply@github.com>
Wed, 11 Sep 2019 15:56:13 +0000 (08:56 -0700)
(cherry picked from commit aa929273caca2f4e24e3aa9e790272fd4458ad35)

Co-authored-by: Steve Dower <steve.dower@python.org>
Misc/NEWS.d/next/Windows/2019-09-11-14-42-04.bpo-36634.8Un8ih.rst [new file with mode: 0644]
Modules/posixmodule.c

diff --git a/Misc/NEWS.d/next/Windows/2019-09-11-14-42-04.bpo-36634.8Un8ih.rst b/Misc/NEWS.d/next/Windows/2019-09-11-14-42-04.bpo-36634.8Un8ih.rst
new file mode 100644 (file)
index 0000000..1affdd8
--- /dev/null
@@ -0,0 +1,2 @@
+:func:`os.cpu_count` now returns active processors rather than maximum
+processors.
index 771c5616152cfddb48756b983aa96765a9a7c5f4..cf6c00b7d6ae7a08190c52ec5579cf1bcc5d910b 100644 (file)
@@ -12176,23 +12176,9 @@ os_cpu_count_impl(PyObject *module)
 {
     int ncpu = 0;
 #ifdef MS_WINDOWS
-    /* Vista is supported and the GetMaximumProcessorCount API is Win7+
-       Need to fallback to Vista behavior if this call isn't present */
-    HINSTANCE hKernel32;
-    static DWORD(CALLBACK *_GetMaximumProcessorCount)(WORD) = NULL;
-    Py_BEGIN_ALLOW_THREADS
-    hKernel32 = GetModuleHandleW(L"KERNEL32");
-    *(FARPROC*)&_GetMaximumProcessorCount = GetProcAddress(hKernel32,
-        "GetMaximumProcessorCount");
-    Py_END_ALLOW_THREADS
-    if (_GetMaximumProcessorCount != NULL) {
-        ncpu = _GetMaximumProcessorCount(ALL_PROCESSOR_GROUPS);
-    }
-    else {
-        SYSTEM_INFO sysinfo;
-        GetSystemInfo(&sysinfo);
-        ncpu = sysinfo.dwNumberOfProcessors;
-    }
+    /* Declare prototype here to avoid pulling in all of the Win7 APIs in 3.8 */
+    DWORD WINAPI GetActiveProcessorCount(WORD group);
+    ncpu = GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
 #elif defined(__hpux)
     ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL);
 #elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)