views:

98

answers:

1

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
ok that works very well, however I'm troubled CPU power used, or is it pretty much efficiency proof?
Asaf
"efficiency proof?" What does that mean? Do you think it uses the CPU while sleeping?
S.Lott
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