In my Mac: MacBook Pro (Retina, 13-inch, Early 2015)
there is the CPU information:
Model: MacBook Pro
Model description: MacBookPro12,1
CPU name: Dual-Core Intel Core i5
CPU rate: 2.7 GHz
CPU number: 1
Core number: 2
When I use Python execute the code:
from multiprocessing import cpu_count
print(cpu_count()) # 4
there output 4
.
Why not 2?
I think multiprocessing.cpu_count()
returns the number of logic cores, not physical ones. For example, I have a surface pro 7, with 4 physical cores and 8 logic ones, and my output is:
>>> print(multiprocessing.cpu_count())
8
Yes multiprocessing.cpu_count()
and os.cpu_count()
will return logical processors. If you want to check logical and physical processors seperately you can use psutil
They can be uses as shown below.
import psutil
print(psutil.cpu_count(logical = False))
print(psutil.cpu_count(logical = True))
output will be
2
4
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.