1

i am trying to make an alarm clock. this uses the time function and check if current time is equal to the alarm time in a while True loop. does it use heavy amount of resources as it check the condition at the maximum frequency it can. is there a way to reduce this frequency so that less processing load is applied to the processor.

1 Answer 1

2

Yes, use time.sleep(). The phenomenon that you're (correctly) trying to avoid is called busy-waiting.

For example, if you wanted to set a ten second delay, you wouldn't want to do:

import time

start = time.time()
while time.time() - start <= 10:
    pass

Instead, you'd want to do:

import time
time.sleep(10)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.