转载:http://www.cnblogs.com/leleroyn/p/4501359.html

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

安装

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

Pip install apscheduler==3.0.3

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

Python setup.py install

cron job例子

#coding=utf-8
from apscheduler.schedulers.blocking import Blocking
Schedulerfrom datetime import datetime
import time
import os   
def tick(): 
    print('Tick! The time is: %s' % datetime.now()) 
 if __name__ == '__main__': 
  scheduler = BlockingScheduler() 
   scheduler.add_job(tick,'cron', second='*/3', hour='*')    
   print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
    try:
         scheduler.start() 
   except (KeyboardInterrupt, SystemExit):
         scheduler.shutdown()

相关文章:

  • 2021-06-16
  • 2022-12-23
  • 2022-01-09
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-07
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-23
相关资源
相似解决方案