Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python os.cpu_count() on Mac returns wrong number of cores

Python's os.cpu_count() returns the wrong number of cores on my Mac.

macOS system report:

  Model Name:   MacBook Pro
  Model Identifier: MacBookPro14,3
  Processor Name:   Quad-Core Intel Core i7
  Processor Speed:  2.9 GHz
  Number of Processors: 1
  Total Number of Cores:    4

Yet os.cpu_count() returns 8.

Is that a bug or I'm missing something?

This is Python 3.8.6; I also checked the Python v2 that comes with the system (using multiprocessing.cpu_count()) and the result is the same.

like image 300
noamtm Avatar asked Jan 27 '26 00:01

noamtm


1 Answers

os.cpu_count() returns the number of logical processors within the machines CPU, also known as threads. If it returns 8 then your machine has 8 threads, not cores.

like image 144
dean0x45 Avatar answered Jan 28 '26 16:01

dean0x45



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!