Making my first python program and try to mimic a crontab.
running : 2.6 with sched module
I need to create a python program which can execute programs at a specific time. so I have a list of schedule such as
[Start_Time], [Action]
Monday 25th September 2009 10:00:00, /opt/prgr/run1.sh
Monday 25th September 2009 11:00:00, /opt/prgr/run2.sh
Monday 25th September 2009 12:00:00, /opt/prgr/run3.sh
...
so based on python sched doc I create something simple just to understand the concept:
Expand|Select|Wrap|Line Numbers
- import time
- import sched
- def timedAction(arg1):
- print arg1
- print time.time()
- s = sched.scheduler(time.time, time.sleep)
- startTime = time.mktime(time.strptime("Aug 29 18:25 2007", '%b %d %H:%M %Y'))
- timer1 = s.enterabs(startTime, 0, timedAction, ("Hello world 1",))
- print "start1:" + str(startTime)
- startTime = time.mktime(time.strptime("Aug 29 18:35 2007", '%b %d %H:%M %Y'))
- print "start2:" + str(startTime)
- timer1 = s.enterabs(startTime, 0, timedAction, ("Hello world 2",))
- s.run()
start1:1188404700.0
start2:1188405300.0
Hello world 1
1251289489.67
Hello world 2
1251289489.67
My understanding is the timedAction function should be executed at:
start1:1188404700.0
start2:1188405300.0
and not at 1251289489.67 which seems to be the case.
I guess I misunderstood to objective and usage of this module. Please could you help here ? I'd like to ensure that the function timedaction start at the right time. By the way, how does sched work from the theorical standpoint. the script is executed and finshed right away but I do not see any deamon running to execture called function. I miss some concept here...
Thanks for your lights
KarXX