Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
497 views
in Technique[技术] by (71.8m points)

Python: Trying to get the number of logical and physical cores on a 3990X, getting the wrong answer?

I'm trying to get the number of physical and logical processors on a given system via Python (v2.7). When I try:

import multiprocessing
print multiprocessing.cpu_count()

I get 64, which is the number of physical processors available on my 3990X. I thought that function gave the number of logical processors available. How do I get that?

question from:https://stackoverflow.com/questions/65865810/python-trying-to-get-the-number-of-logical-and-physical-cores-on-a-3990x-getti

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First of all, congratulations on owning a 3990X!

os.cpu_count() (or equivalently multiprocessing.cpu_count()) is supposed to report the number of logical cores like you stated.

The issue you experienced seems to be a known bug in Python that appears fixed in Python 3.6 and above. Windows uses a 64-bit bitmask to keep track of CPU cores, so many applications can run into issues when run on systems with more than 64 logical cores.

I highly recommend to stop using Python 2.7 as it has reached its end-of-life on January 1st 2020. Python 2 will not be getting any new features or bugfixes, and this is likely one of them.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...