repost: http web page fetch question

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat Apr 25 07:54:14 CEST 2009


En Fri, 24 Apr 2009 11:54:40 -0300, grocery_stocker <cdalten at gmail.com>  
escribió:

> scheduler = sched.scheduler(time.time, time.sleep)
>
> How do I modify it so that it runs every hour on the hour.

(The sched module is almost useless, IMHO)

I'd use cron (linux) or schtasks (windows).
If it has to be a Python script, I'd just use time.sleep:

def compute_delay_until_next_hour():
   now = time.localtime()
   secs_past_hour = now.tm_min * 60 + now.tm_sec
   delay = 60*60 - secs_past_hour
   return delay

# do_something() # optional
while True:
   dt = compute_delay_until_next_hour()
   time.sleep(dt)
   do_something()

-- 
Gabriel Genellina




More information about the Python-list mailing list