Python定时调度--多任务同一时间开始跑 scheduler.enterabs
2015-08-20 17:22
726 查看
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数据类型详解
- 安装numpy和matplotlib简单又不易出错的方法
- python的sorted函数对字典按key排序和按value排序
- LeetCode 135:candy 题解 Python
- python 获取股票的交易数据
- Quick to learn Python rules
- Python中的urllib2
- python开发之Tkinter可视化
- ubuntu下安装numpy,matplotlib
- python+Eclipse+pydev环境搭建
- python __name__ == '__main__'解析
- python __init__.py文件的作用
- python动态按区域显示
- 装饰器与函数式Python(译)
- 在类Unix系统上开始Python3编程入门
- Python的sched模块
- [Python爬虫] Selenium自动访问Firefox和Chrome并实现搜索截图
- Python中字典映射类型的学习教程
- 浅淡Python 3.x中encode、decode方法
- python正则表达式几个例子