Rilcon42
Rilcon42

Reputation: 9765

python schedule recurring event given only time in am/pm format

I am trying to to set a recurring event (running a python script) at a set time (9am EST, US in this case). The only way I found to do this was to manually calculate the miliseconds for the first time and increment them by 24 hours to schedule the next day. Is there a better way?

#!/usr/bin/python
import sched
import time

time_in_ms=???
scheduler = sched.scheduler(time.time, time.sleep)

def my_event(name):
    import room_light.py


print 'START:', time.time()
scheduler.enterabs(time_in_ms, 1, my_event, ('',))
scheduler.run()

Upvotes: 0

Views: 421

Answers (1)

Andrii Liakh
Andrii Liakh

Reputation: 619

You can just use cron jobs. This is the best way to schedule tasks.

Update: it's an OS feature, not Python.

Upvotes: 1

Related Questions