安排运行脚本的时间和日期 [英] Schedule time and date to run script
本文介绍了安排运行脚本的时间和日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试找到一个可以在Python中执行以下操作的软件包:
I'm trying to find a package that can do the following in Python:
- 添加/删除指定的日期和时间
- 将其添加/删除到调度程序中
我看过的东西:
- https: //docs.python.org/2/library/sched.html
- 看起来它只显示时间,而不显示日期。
- 重复几天,但没有特定日期。
推荐答案
您可以使用sched来做到这一点。
You can use sched to do that.
sched.add_job(job_func, trigger='interval', hours=3, start_date='2015-10-10 09:30', end_date='2015-11-10 09:30')
您可以传递参数进行触发。这会将其设置为从2015-10-10 09:30到2015-10-10 09:30每天运行3个小时。 间隔触发器进行设置日期。您还可以将小时与周,小时,天等交换,希望对您有所帮助!
You can pass arguments for trigger. This would set it up to run for 3 hours each day from 2015-10-10 09:30 to until 2015-10-10 09:30. Interval trigger to set up dates. You can also interchange hours with weeks, hours, days, etc. Hope this helps!
以下是一些使用apscheduler的示例。
Here's some examples using apscheduler.
from apscheduler.schedulers.blocking import BlockingScheduler sched = BlockingScheduler() @sched.scheduled_job('interval', seconds=60) def timed_job(): print('This job is run every minute.') @sched.scheduled_job('cron', day_of_week='mon-fri', hour=17) def scheduled_job(): print('This job is run every weekday at 5pm.') sched.start()
这篇关于安排运行脚本的时间和日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文