Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thefab/cpu_cores
A small python library and utility to get the number of "physical" cpu cores (without hyperthreading logical cores) of a linux/osx box
https://github.com/thefab/cpu_cores
Last synced: about 1 month ago
JSON representation
A small python library and utility to get the number of "physical" cpu cores (without hyperthreading logical cores) of a linux/osx box
- Host: GitHub
- URL: https://github.com/thefab/cpu_cores
- Owner: thefab
- License: mit
- Created: 2013-08-29T13:31:39.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2022-09-05T11:43:27.000Z (about 2 years ago)
- Last Synced: 2024-10-05T18:36:00.273Z (about 1 month ago)
- Language: Python
- Size: 195 KB
- Stars: 2
- Watchers: 4
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
# cpu_cores
## Status (master branch)
[![Build Status](https://travis-ci.org/thefab/cpu_cores.png)](https://travis-ci.org/thefab/cpu_cores)
## What is it ?
`cpu_cores` is small python library and utility to get the number of "physical" cpu cores (without hyperthreading logical cores) of a linux/osx box.
On Linux, this is not an easy task because of hyperthreaded logical cores included in `/proc/cpuinfo`. Please, read carefully [this excellent post](http://www.richweb.com/cpu_info) to understand why.
## Special features
- support Linux (well tested) and OSX (needs some extra tests files), easy to extend to support other OS
- unit tests (> 90% coverage)
- python2 and python3 support
- no dependencies## Warning
`cpu_cores` is at an early stage of development (API can change).
If you have exotic Linux or OSX boxes with plenty of cpu cores, please provides the output of :
# For Linux
cat /proc/cpuinfoor
# For OSX
/usr/sbin/system_profiler -detailLevel full SPHardwareDataType## Quickstart
### Installation
pip install cpu_cores
Requirements:
- Python 2.6, 2.7, 3.2 or 3.3## Two ways to use it
### As a python library
#!/usr/bin/env python
# Import
from cpu_cores import CPUCoresCounter# We build an instance for the current operating system
instance = CPUCoresCounter.factory()# Get the number of total real cpu cores
print instance.get_physical_cores_count()# Get the number of total physical processors
print instance.get_physical_processors_count()### As a CLI utility
prompt$ get_cpu_physical_cores.py
Number of real physical processors : 1
Number of real physical cores : 2prompt$ get_cpu_physical_cores.py --single-value=cores
2prompt$ get_cpu_physical_cores.py --single-value=processors
1