mirror of
https://github.com/python/cpython.git
synced 2025-11-13 15:40:05 +00:00
bpo-33166: Change os.cpu_count to return active (real) processors (GH-15949)
This commit is contained in:
parent
e20134f889
commit
aa929273ca
2 changed files with 5 additions and 17 deletions
|
|
@ -0,0 +1,2 @@
|
||||||
|
:func:`os.cpu_count` now returns active processors rather than maximum
|
||||||
|
processors.
|
||||||
|
|
@ -12204,23 +12204,9 @@ os_cpu_count_impl(PyObject *module)
|
||||||
{
|
{
|
||||||
int ncpu = 0;
|
int ncpu = 0;
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
/* Vista is supported and the GetMaximumProcessorCount API is Win7+
|
/* Declare prototype here to avoid pulling in all of the Win7 APIs in 3.8 */
|
||||||
Need to fallback to Vista behavior if this call isn't present */
|
DWORD WINAPI GetActiveProcessorCount(WORD group);
|
||||||
HINSTANCE hKernel32;
|
ncpu = GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
|
||||||
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;
|
|
||||||
}
|
|
||||||
#elif defined(__hpux)
|
#elif defined(__hpux)
|
||||||
ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL);
|
ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL);
|
||||||
#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
|
#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue