diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-09-11 15:56:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-11 15:56:13 (GMT) |
commit | 43ee0e2ca33ae28d37a3dddf10a648895cd46bda (patch) | |
tree | e00e04f811ee3a7f4477315f764b02c14c5037d5 /Modules | |
parent | 63eefc35674ec12ab4d00af4feaf21de4cb1c91c (diff) | |
download | cpython-43ee0e2ca33ae28d37a3dddf10a648895cd46bda.zip cpython-43ee0e2ca33ae28d37a3dddf10a648895cd46bda.tar.gz cpython-43ee0e2ca33ae28d37a3dddf10a648895cd46bda.tar.bz2 |
bpo-33166: Change os.cpu_count to return active (real) processors (GH-15949)
(cherry picked from commit aa929273caca2f4e24e3aa9e790272fd4458ad35)
Co-authored-by: Steve Dower <steve.dower@python.org>
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/posixmodule.c | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 771c561..cf6c00b 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -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) |