Cpu stress o meter project

why we are not running the while loop after every 10 seconds in the cpu stress o meter ?isn’t that if we do not use time.sleep(10) api requests per minute will increase and access can be denied?
if the above can happen would it be ok if i write time.sleep(!0) in cpu stress o meter code or there is no chance that access can be denied if i do not write it?

Hi @jain.reechika,

interval = 10
while True:
    cpu_usage = psutil.cpu_percent(interval = interval)
    print "CPU usage is", cpu_usage
    if cpu_usage > cpu_red_threshold:
        control_green_led('0','LOW')
        control_red_led('1', 'HIGH')
        control_red_led('2', 'LOW')
    else:
        control_green_led('0', 'HIGH')
        control_red_led('1', 'LOW') 

The below line itself wait for the 10 second to check the cpu status/

cpu_usage = psutil.cpu_percent(interval = interval)

But in case your interval is less that 10 seconds then you must add the time.sleep() to avoid api blocking.

Do let me know in case you need further assistance.

Hi@rahul.singh1

What’s the max and min stress that cpu can hold, how do we set threshold value

@surasahityasagar

It’s not a particular CPU the project was about.

Your Stress percentage level depends on the number of applications and windows your PC has open. Including how much heavy a software is.

You can check your CPU stress from the Task Manager (windows) > Performance > CPU stress.

Threshold value was taken as 40%. Your threshold value could be determined by you.

Let me know if you need any other information.

I have mentioned already. Here 40% refers to 0.4 value.

1 Like

Thank you now I got it