Python定时调度--多任务同一时间开始跑 scheduler.enterabs,,Event Prio


Event Priorities

If more than one event is scheduled for the same time their priority values are used to determine the order they are run.

import schedimport timescheduler = sched.scheduler(time.time, time.sleep)def print_event(name):    print ‘EVENT:‘, time.time(), namenow = time.time()print ‘START:‘, nowscheduler.enterabs(now+2, 2, print_event, (‘first‘,))scheduler.enterabs(now+2, 1, print_event, (‘second‘,))scheduler.run()

This example needs to ensure that they are scheduled for the exact same time, so theenterabs()method is used instead ofenter(). The first argument toenterabs()is the time to run the event, instead of the amount of time to delay. The second argument is the priority value, smaller number is more prioriable.

$ python sched_priority.pySTART: 1361446608.62EVENT: 1361446610.62 secondEVENT: 1361446610.62 first

Python定时调度--多任务同一时间开始跑 scheduler.enterabs

相关内容

    暂无相关文章

评论关闭