zoukankan      html  css  js  c++  java
  • Python定时任务框架APScheduler 3.0.3 Cron示例

    APScheduler是基于Quartz的一个Python定时任务框架,实现了Quartz的所有功能,使用起来十分方便。提供了基于日期、固定时间间隔以及crontab类型的任务,并且可以持久化任务。基于这些功能,我们可以很方便的实现一个python定时任务系统

    安装

    安装过程很简单,可以基于pip和源码。

    Pip install apscheduler==3.0.3

    或者下载源码,运行命令:

    Python setup.py install

    cron job例子

       1:  #coding=utf-8
       2:  from apscheduler.schedulers.blocking import BlockingScheduler
       3:  from datetime import datetime
       4:  import time
       5:  import os
       6:     
       7:  def tick():
       8:      print('Tick! The time is: %s' % datetime.now())
       9:   
      10:  if __name__ == '__main__':
      11:      scheduler = BlockingScheduler()
      12:      scheduler.add_job(tick,'cron', second='*/3', hour='*')    
      13:      print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
      14:      try:
      15:          scheduler.start()
      16:      except (KeyboardInterrupt, SystemExit):
      17:          scheduler.shutdown() 
      18:   
      19:   
      20:   

    Cron表达 式说明

    Expression

    Field

    Description

    *

    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

  • 相关阅读:
    圆圈中最后剩下的数字 【微软面试100题 第十八题】
    第一个只出现一次的字符 【微软面试100题 第十七题】
    从上往下打印二叉树 【微软面试100题 第十六题】
    二叉树的镜像 【微软面试100题 第十五题】
    和为s的两个数字 【微软面试100题 第十四题】
    链表中倒数第k个结点 【微软面试100题 第十三题】
    求1+2+...+n 【微软面试100题 第十二题】
    求二叉树中结点的最大距离 【微软面试100题 第十一题】
    翻转句子中单词的顺序 【微软面试100题 第十题】
    二叉搜索树的后序遍历序列 【微软面试100题 第九题】
  • 原文地址:https://www.cnblogs.com/leleroyn/p/4501359.html
Copyright © 2011-2022 走看看