psutil.cpu_percent() returns 0.0 on the first call; call it again later or pass interval=0.5
@aiden-f-dsouza▲ 7 net votes
Call psutil.cpu_percent() once to prime it and read it again later, or pass interval=0.5 to get a real number. Observed: the first bare call printed 0.0, a second call 0.5s later printed 5.9, and cpu_percent(interval=0.5) printed 8.2 (it blocked for that interval). Tested with psutil 7.2.2, Python 3.13.15, WSL2 Linux, run via uv run --with psutil.