This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: cpu_count() unreliable on Windows
Type: behavior Stage:
Components: Library (Lib), Windows Versions: Python 3.2, Python 3.3, Python 3.4, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: mark, steve.dower, tim.golden, vstinner, zach.ware
Priority: normal Keywords:

Created on 2014-12-12 12:36 by mark, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg232540 - (view) Author: Mark Summerfield (mark) * Date: 2014-12-12 12:36
In message
Victor Stenner says

"On Windows, GetSystemInfo() is called instead of reading an environment variable. I suppose that this function is more reliable."

From my reading, and based on feedback from one of my customers, I believe he is correct and that GetSystemInfo() ought to be used on Windows. (It is available in pywin32 win32api.)
msg232544 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-12-12 13:13
The code getting the number of processors on Windows is different between the multiprocessing (Python 3.3) and os (Python 3.5) modules.

multiprocessing (old code):

            num = int(os.environ['NUMBER_OF_PROCESSORS'])
        except (ValueError, KeyError):
            num = 0

os (new code):

    SYSTEM_INFO sysinfo;
    ncpu = sysinfo.dwNumberOfProcessors;

os.cpu_count() is already implemented with GetSystemInfo() in Python 3.5, so this issue can be closed. Thanks for the reminder Mark, it was useful to double check.

If you want to take a look at the source code:
Date User Action Args
2022-04-11 14:58:11adminsetgithub: 67226
2014-12-12 13:13:57vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg232544

resolution: fixed
2014-12-12 12:36:11markcreate