os.cpu_count()
is used to get the number of CPUs in a system. It does not take any argument value and returns the total CPU count as an integer. Otherwise, it returns none.
The
Note: It does not return the count of CPUs that can be used by the current process. Instead, it returns the count of the total CPUs in a system.
# Signatureos.cpu_count()
It returns the following values.
int
: This refers to the number of CPUs in a system as an integer value.None
: None
is returned if the number of CPUs is undetermined.Let's take a look at a code example.
# Program for os.cpu_count()# import os moduleimport os# Extract CPUs countCPUs = os.cpu_count()# print resultsprint("Total CPUs count:", CPUs)
In the code snippet above, we invoke the cpu_count()
from the OS module to extract the count of CPUs.
cpu_count()
to get either the CPUs in the system as an integer value or None
.