'if there is a infinite loop in a python code, is it harmful or use large amount of resources?
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.
Solution 1:[1]
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)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
