Number of CPUs

EasyOS Module Programs · 42 of 49

Write a Python program to get the number of CPUs with os.cpu_count().

Advertisement
Output
int True

Approach

  1. It returns an int, or None if unknown.

Solution

Python
import os n = os.cpu_count()print(type(n).__name__, n is not None and n >= 1)
Output
int True
Note

The real number depends on your machine, which is why the example prints a check.

Learn the concept

New to this topic? Read the lesson, then come back.

More os module programs

← All 49 OS Module Programs

Leave a Comment