python调度框架APScheduler使用详解
# coding=utf-8
"""
Demonstrates how to use the background scheduler to schedule a job that executes on 3 second
intervals.
""" from datetime import datetime
import time
import os from apscheduler.schedulers.background import BackgroundScheduler def tick():
print('Tick! The time is: %s' % datetime.now()) if __name__ == '__main__':
scheduler = BackgroundScheduler()
scheduler.add_job(tick, 'interval', seconds=3) #间隔3秒钟执行一次
scheduler.start() #这里的调度任务是独立的一个线程
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) try:
# This is here to simulate application activity (which keeps the main thread alive).
while True:
time.sleep(2) #其他任务是独立的线程执行
print('sleep!')
except (KeyboardInterrupt, SystemExit):
# Not strictly necessary if daemonic mode is enabled but should be done if possible
scheduler.shutdown()
print('Exit The Job!')
非阻塞调度,在指定的时间执行一次
# coding=utf-8
"""
Demonstrates how to use the background scheduler to schedule a job that executes on 3 second
intervals.
""" from datetime import datetime
import time
import os from apscheduler.schedulers.background import BackgroundScheduler def tick():
print('Tick! The time is: %s' % datetime.now()) if __name__ == '__main__':
scheduler = BackgroundScheduler()
#scheduler.add_job(tick, 'interval', seconds=3)
scheduler.add_job(tick, 'date', run_date='2016-02-14 15:01:05') #在指定的时间,只执行一次
scheduler.start() #这里的调度任务是独立的一个线程
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) try:
# This is here to simulate application activity (which keeps the main thread alive).
while True:
time.sleep(2) #其他任务是独立的线程执行
print('sleep!')
except (KeyboardInterrupt, SystemExit):
# Not strictly necessary if daemonic mode is enabled but should be done if possible
scheduler.shutdown()
print('Exit The Job!')
非阻塞的方式,采用cron的方式执行
# coding=utf-8
"""
Demonstrates how to use the background scheduler to schedule a job that executes on 3 second
intervals.
""" from datetime import datetime
import time
import os from apscheduler.schedulers.background import BackgroundScheduler def tick():
print('Tick! The time is: %s' % datetime.now()) if __name__ == '__main__':
scheduler = BackgroundScheduler()
#scheduler.add_job(tick, 'interval', seconds=3)
#scheduler.add_job(tick, 'date', run_date='2016-02-14 15:01:05')
scheduler.add_job(tick, 'cron', day_of_week='', second='*/5')
'''
year (int|str) – 4-digit year
month (int|str) – month (1-12)
day (int|str) – day of the (1-31)
week (int|str) – ISO week (1-53)
day_of_week (int|str) – number or name of weekday (0-6 or mon,tue,wed,thu,fri,sat,sun)
hour (int|str) – hour (0-23)
minute (int|str) – minute (0-59)
second (int|str) – second (0-59) start_date (datetime|str) – earliest possible date/time to trigger on (inclusive)
end_date (datetime|str) – latest possible date/time to trigger on (inclusive)
timezone (datetime.tzinfo|str) – time zone to use for the date/time calculations (defaults to scheduler timezone) * any Fire on every value
*/a any Fire every a values, starting from the minimum
a-b any Fire on any value within the a-b range (a must be smaller than b)
a-b/c any Fire every c values within the a-b range
xth y day Fire on the x -th occurrence of weekday y within the month
last x day Fire on the last occurrence of weekday x within the month
last day Fire on the last day within the month
x,y,z any Fire on any matching expression; can combine any number of any of the above expressions
'''
scheduler.start() #这里的调度任务是独立的一个线程
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) try:
# This is here to simulate application activity (which keeps the main thread alive).
while True:
time.sleep(2) #其他任务是独立的线程执行
print('sleep!')
except (KeyboardInterrupt, SystemExit):
# Not strictly necessary if daemonic mode is enabled but should be done if possible
scheduler.shutdown()
print('Exit The Job!')
阻塞的方式,间隔3秒执行一次
# coding=utf-8
"""
Demonstrates how to use the background scheduler to schedule a job that executes on 3 second
intervals.
""" from datetime import datetime
import os from apscheduler.schedulers.blocking import BlockingScheduler def tick():
print('Tick! The time is: %s' % datetime.now()) if __name__ == '__main__':
scheduler = BlockingScheduler()
scheduler.add_job(tick, 'interval', seconds=3) print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) try:
scheduler.start() #采用的是阻塞的方式,只有一个线程专职做调度的任务
except (KeyboardInterrupt, SystemExit):
# Not strictly necessary if daemonic mode is enabled but should be done if possible
scheduler.shutdown()
print('Exit The Job!')
采用阻塞的方法,只执行一次
# coding=utf-8
"""
Demonstrates how to use the background scheduler to schedule a job that executes on 3 second
intervals.
""" from datetime import datetime
import os from apscheduler.schedulers.blocking import BlockingScheduler def tick():
print('Tick! The time is: %s' % datetime.now()) if __name__ == '__main__':
scheduler = BlockingScheduler()
scheduler.add_job(tick, 'date', run_date='2016-02-14 15:23:05') print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) try:
scheduler.start() #采用的是阻塞的方式,只有一个线程专职做调度的任务
except (KeyboardInterrupt, SystemExit):
# Not strictly necessary if daemonic mode is enabled but should be done if possible
scheduler.shutdown()
print('Exit The Job!')
采用阻塞的方式,使用cron的调度方法
# coding=utf-8
"""
Demonstrates how to use the background scheduler to schedule a job that executes on 3 second
intervals.
""" from datetime import datetime
import os from apscheduler.schedulers.blocking import BlockingScheduler def tick():
print('Tick! The time is: %s' % datetime.now()) if __name__ == '__main__':
scheduler = BlockingScheduler()
scheduler.add_job(tick, 'cron', day_of_week='', second='*/5')
'''
year (int|str) – 4-digit year
month (int|str) – month (1-12)
day (int|str) – day of the (1-31)
week (int|str) – ISO week (1-53)
day_of_week (int|str) – number or name of weekday (0-6 or mon,tue,wed,thu,fri,sat,sun)
hour (int|str) – hour (0-23)
minute (int|str) – minute (0-59)
second (int|str) – second (0-59) start_date (datetime|str) – earliest possible date/time to trigger on (inclusive)
end_date (datetime|str) – latest possible date/time to trigger on (inclusive)
timezone (datetime.tzinfo|str) – time zone to use for the date/time calculations (defaults to scheduler timezone) * any Fire on every value
*/a any Fire every a values, starting from the minimum
a-b any Fire on any value within the a-b range (a must be smaller than b)
a-b/c any Fire every c values within the a-b range
xth y day Fire on the x -th occurrence of weekday y within the month
last x day Fire on the last occurrence of weekday x within the month
last day Fire on the last day within the month
x,y,z any Fire on any matching expression; can combine any number of any of the above expressions
''' print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) try:
scheduler.start() #采用的是阻塞的方式,只有一个线程专职做调度的任务
except (KeyboardInterrupt, SystemExit):
# Not strictly necessary if daemonic mode is enabled but should be done if possible
scheduler.shutdown()
print('Exit The Job!')
python调度框架APScheduler使用详解的更多相关文章
- django定时任务python调度框架APScheduler使用详解
# coding=utf-8 2 """ 3 Demonstrates how to use the background scheduler to schedule a ...
- 定时任务框架APScheduler学习详解
APScheduler简介 在平常的工作中几乎有一半的功能模块都需要定时任务来推动,例如项目中有一个定时统计程序,定时爬出网站的URL程序,定时检测钓鱼网站的程序等等,都涉及到了关于定时任务的问题,第 ...
- python爬虫框架scrapy实例详解
生成项目scrapy提供一个工具来生成项目,生成的项目中预置了一些文件,用户需要在这些文件中添加自己的代码.打开命令行,执行:scrapy st... 生成项目 scrapy提供一个工具来生成项目,生 ...
- Django框架 之 querySet详解
Django框架 之 querySet详解 浏览目录 可切片 可迭代 惰性查询 缓存机制 exists()与iterator()方法 QuerySet 可切片 使用Python 的切片语法来限制查询集 ...
- Python API 操作Hadoop hdfs详解
1:安装 由于是windows环境(linux其实也一样),只要有pip或者setup_install安装起来都是很方便的 >pip install hdfs 2:Client——创建集群连接 ...
- java的集合框架最全详解
java的集合框架最全详解(图) 前言:数据结构对程序设计有着深远的影响,在面向过程的C语言中,数据库结构用struct来描述,而在面向对象的编程中,数据结构是用类来描述的,并且包含有对该数据结构操作 ...
- Python安装、配置图文详解(转载)
Python安装.配置图文详解 目录: 一. Python简介 二. 安装python 1. 在windows下安装 2. 在Linux下安装 三. 在windows下配置python集成开发环境(I ...
- 【和我一起学python吧】Python安装、配置图文详解
Python安装.配置图文详解 目录: 一. Python简介 二. 安装python 1. 在windows下安装 2. 在Linux下安装 三. 在windows下配置python集成开发环境( ...
- Python中的高级数据结构详解
这篇文章主要介绍了Python中的高级数据结构详解,本文讲解了Collection.Array.Heapq.Bisect.Weakref.Copy以及Pprint这些数据结构的用法,需要的朋友可以参考 ...
随机推荐
- AngularJS 作用域与数据绑定机制
AngularJS 简介 AngularJS 是由 Google 发起的一款开源的前端 MVC 脚本框架,既适合做普通 WEB 应用也可以做 SPA(单页面应用,所有的用户操作都在一个页面中完成).与 ...
- linux用户登录
一.linux用户登录过程访问的文件 /etc/passwd---用户登录时,linux会先到这里查看用户Id.组Id.登录后的shell.用户工作目录 /etc/shadow(影)---linux在 ...
- python collections(容器)模块
原文:http://docs.pythontab.com/interpy/collections/collections/ 容器(Collections) Python附带一个模块,它包含许多容器数据 ...
- uva11019矩阵匹配器D316
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #inclu ...
- J.U.C并发框架源码阅读(十四)ScheduledThreadPoolExecutor
基于版本jdk1.7.0_80 java.util.concurrent.ScheduledThreadPoolExecutor 代码如下 /* * ORACLE PROPRIETARY/CONFID ...
- thinkphp函数学习(2)——microtime, memory_get_usage, dirname, strtolower, is_file
1. microtime() 返回 微秒 秒 这种格式的内容 例子 <?php echo(microtime()); ?> 输出: 0.25139300 1138197510 // 前 ...
- Python与数据结构[0] -> 链表/LinkedList[0] -> 单链表与带表头单链表的 Python 实现
单链表 / Linked List 目录 单链表 带表头单链表 链表是一种基本的线性数据结构,在C语言中,这种数据结构通过指针实现,由于存储空间不要求连续性,因此插入和删除操作将变得十分快速.下面将利 ...
- 用SparkSQL构建用户画像
用SparkSQL构建用户画像 二. 前言 大数据时代已经到来,企业迫切希望从已经积累的数据中分析出有价值的东西,而用户行为的分析尤为重要. 利用大数据来分析用户的行为与消费习惯,可以预测商品的发展 ...
- C++ 二位数组做参数传递
指针的强大功能,,,,简直牛逼!!! #include<iostream> #include<cstdio> #include<map> using namespa ...
- [CP1804]最短路
题目大意: 一个$n(n\le10^5)$个点的图,给定一个常数$c$,每对点$i,j$之间有权值为$(i\oplus j)\times c$的边.另有$m(m\le5\times10^5)$条指定权 ...