I want to run a program that runs a function every 4 hours. What is the least consuming way to do so?
+3
A:
Simlest way I can think of (in python since the post is tagged with python):
import time
while True:
do_task()
time.sleep(4 * 60 * 60) # 4 hours * 60 minutes * 60 seconds
Bryan Ross
2010-05-17 19:28:17
ok that works very well, however I'm troubled CPU power used, or is it pretty much efficiency proof?
Asaf
2010-05-17 19:35:17
"efficiency proof?" What does that mean? Do you think it uses the CPU while sleeping?
S.Lott
2010-05-17 20:42:10
It's pretty much safe to say that it just puts the process to sleep. Virtually zero CPU use until it wakes up.
Bryan Ross
2010-05-17 21:02:21