首页 > 编程语言 > 详细

python 定时任务执行

时间:2020-06-18 14:28:48      阅读:72      评论:0      收藏:0      [点我收藏+]

 

最好用的是APScheduler定时框架

可以使用schedule和apschedule模块,其中最好用的是APScheduler定时框架

使用 APScheduler 需要安装

$ pip install apscheduler

 

首先来看一个周一到周五每天早上6点半定时打印的例子

from apscheduler.schedulers.blocking import BlockingScheduler
from datetime import datetime
# 输出时间
def job():
    print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
# BlockingScheduler
scheduler = BlockingScheduler()
scheduler.add_job(job, cron, day_of_week=1-5, hour=6, minute=30)
scheduler.start()

该模块有三种调用方式date, cron和interval

sched.add_job(job, ‘interval‘, seconds=5)
sched.add_job(my_job, ‘date‘, run_date=date(2009, 11, 6), args=[‘text‘])

 

转自:https://www.cnblogs.com/fengff/p/11011000.html

python 定时任务执行

原文:https://www.cnblogs.com/i-shu/p/13157073.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!