首页 > 编程语言 > 详细

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

时间:2015-08-20 18:21:46      阅读:342      评论:0      收藏:0      [点我收藏+]

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 sched
import time

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

def print_event(name):
    print EVENT:, time.time(), name

now = time.time()
print START:, now
scheduler.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 the enterabs() method is used instead of enter(). The first argument to enterabs() 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.py

START: 1361446608.62
EVENT: 1361446610.62 second
EVENT: 1361446610.62 first

 

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

原文:http://www.cnblogs.com/100thMountain/p/4745835.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!