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

Viewed 489

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.

2 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.

os.cpu_count() means threads not cores.

Related