- 1 year ago
Getting the total CPU usage in python 3 on windows
Comment
1 / 1
To get the total CPU usage in Python 3 on Windows, you can use the psutil
module. Here's an example code that demonstrates how to use the psutil
module to get the total CPU usage:
pythonimport psutil
# Get the total CPU usage
cpu_usage = psutil.cpu_percent()
# Print the total CPU usage
print("Total CPU usage:", cpu_usage, "%")
In this example, the psutil.cpu_percent()
method is used to get the total CPU usage as a percentage. The returned value represents the average CPU usage since the last time the method was called. Note that the psutil
module must be installed in order to use it. You can install it using pip install psutil
command in your command prompt.