[Rod Stephens Books]
Index Books Python Examples About Rod Contact
[Mastodon] [Bluesky] [Facebook]
[Build Your Own Python Action Arcade!]

[Build Your Own Ray Tracer With Python]

[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

Title: Check CPU usage in Python

[This system's CPU is 7.3% used]

This is another unglamorous example that may be useful under some circumstances. It's super short so here it is in its entirety.

import psutil cpu_percent = psutil.cpu_percent(interval=1) print(f'CPU: {cpu_percent / 100:.2%}')

The psutil.cpu_percent function returns the fraction of the CPU time used. The interval parameter tells it how long to wait while tallying the usage. In this example, it gets the CPU usage statistics, waits 1 second, gets the statistics again, and compares the two values to see how much the CPU was used during that 1 second.

That's all there is to it. Download the example to experiment with it and to see additional details.

© 2025 Rocky Mountain Computer Consulting, Inc. All rights reserved.