本篇文章主要介绍了详解python调度框架APScheduler使用,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

最近在研究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='6', 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='6', 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 阻塞方式只用一个线程_框架APScheduler在python中调度使用的实例详解...相关推荐

  1. python中label有什么用_对Python中TKinter模块中的Label组件实例详解

    Python2.7.4 OS-W7x86 1. 简介 Label用于在指定的窗口中显示文本和图像.最终呈现出的Label是由背景和前景叠加构成的内容. Label组件定义函数:Label(master ...

  2. python decimal类型转化_python中的decimal类型转换实例详解

    [Python标准库]decimal--定点数和浮点数的数学运算 作用:使用定点数和浮点数的小数运算. Python 版本:2.4 及以后版本 decimal 模块实现了定点和浮点算术运算符,使用的是 ...

  3. python迭代器创建序列_Python 中迭代器与生成器实例详解

    Python 中迭代器与生成器实例详解 本文通过针对不同应用场景及其解决方案的方式,总结了Python中迭代器与生成器的一些相关知识,具体如下: 1.手动遍历迭代器 应用场景:想遍历一个可迭代对象中的 ...

  4. python编程字典100例_python中字典(Dictionary)用法实例详解

    本文实例讲述了python中字典(Dictionary)用法.分享给大家供大家参考.具体分析如下: 字典(Dictionary)是一种映射结构的数据类型,由无序的"键-值对"组成. ...

  5. python2与python3性能对比_对Python2与Python3中__bool__方法的差异详解

    对Python2与Python3中__bool__方法的差异详解 发布时间:2020-08-28 00:08:58 来源:脚本之家 阅读:74 作者:grey_csdn 学习Python面向对象编程的 ...

  6. python把数据写入excel_Python读写sqlite3数据库的方法并且将数据写入Excel的实例详解...

    这篇文章主要介绍了Python实现读写sqlite3数据库并将统计数据写入Excel的方法,涉及Python针对sqlite3数据库的读取及Excel文件相关操作技巧,需要的朋友可以参考下 本文实例讲 ...

  7. python量化实战 顾比倒数线_顾比倒数线的画法及使用条件详解

    顾比倒数线的画法及使用条件详解 顾比线是 [ 澳 ] 诺.顾比提出的,以概率为基础阐述了趋势突破确认.介入触发点.止损 触发点.损失不大于资产 2% 的仓位控制.最大追涨位等.指标中含倒数线和均线束. ...

  8. python类初始化导入库_Python中optparser库用法实例详解

    本文研究的主要是Python中optparser库的相关内容,具体如下. 一直以来对optparser不是特别的理解,今天就狠下心,静下心研究了一下这个库.当然了,不敢说理解的很到位,但是足以应付正常 ...

  9. python笔记小白入门_Python 笔记:全网最详细最小白的Class类和实例详解

    面向对象最重要的概念就是类(class)和实例(instance),类是抽象,而实例(Instance)则是一个个具体的对象 面向对象三大特点:封装.继承和多态 class Animal(object ...

最新文章

  1. web.config文件
  2. 一个普通80后的IT Pro去溜冰的感慨
  3. 查找内存泄漏的一个思路
  4. eclipse编码设置
  5. 学会这几个公式技巧,瞬间你就是高手
  6. 曲线抽稀 java_Python实现曲线点抽稀算法
  7. Hi3516A开发--挂载SD卡和U盘
  8. C#语言基础——结构体和枚举类型
  9. react 组件引用组件_React Elements VS React组件
  10. E72上安装fring使用skypeout拨打电话
  11. 轻量级网络模型之EfficientNet
  12. 如何让php支持mysql的,怎么让php支持MySql
  13. vs2008的简单使用
  14. java生成pdf417条形码_python生成417条形码(PDF417)
  15. c#开发的一套完整的题库管理系统
  16. Python(pybrain模块)搭建神经网络BPNN
  17. 读债务危机0814-08年9月崩溃
  18. 《赋予角色移动时的动画》part02——动画蓝图
  19. 如何在阿里云免费 SSL 证书到期后更新证书操作步骤
  20. vue子元素点击事件与父元素点击事件冲突 子元素点击事件不触发

热门文章

  1. 高效使用PC需要记住的快捷键
  2. CSS中常见的长度单位
  3. iOS - OC PList 数据存储
  4. [BZOJ3874/AHOI2014]宅男计划
  5. 逆序数 UVALive 6508 Permutation Graphs
  6. expandableListView 总结
  7. 25 个超棒的 WordPress 主题(2012)
  8. IBM X3650 WIN2003安装详细方法
  9. HTML用a标签出现404,404.html
  10. 【IDEA】干掉注释自动在行首