Closed Crilum closed 2 years ago
Seems like your error. Just remove /1000 from get_cpu_percent().
def get_cpu_percent(): # get CPU usage
cpuper = psutil.cpu_percent(interval=0.5) # <-- It returns value in %, so for 50% it returns 50.0 etc
return '{:.2f}'.format( float(cpuper)/1000 ) + ' %' # <-- Here you are dividing by 1000, so your 50.0 becomes 0.05
Ahh, thanks!
Summary
Description
I'm editing a script that displays CPU Temp and Time on an LCD screen, and instead of having CPU Temp and Time, I wanted to have CPU usage in percent, and the CPU frequency, so I made a function for both:
and called it in a loop:
and ran the loop.
And it worked, but the
get_cpu_percent()
function showsCPU %: 0.03
on the LCD when called in the loop. The3
is an echo of every 10%, so if the CPU were running at 50%, the LCD would showCPU %: 0.05
, and if the CPU were running at 100%, the LCD would showCPU %: 0.10
(theoretically, I haven't used the CPU at 100% to test..), and so on and so forth.. The frequency function worked fine.If this is a user error, sorry.. I'm new to python..
This is the whole script: