lqh*_*gbl 2 python apscheduler
我正在使用Python apscheduler处理期间任务,我希望代码在每天的9:00,11:00,16:00,17:00执行,这里是作业的示例代码:
#coding=utf-8
from apscheduler.schedulers.blocking import BlockingScheduler
import logging
logging.basicConfig()
from time import ctime
sched = BlockingScheduler()
@sched.scheduled_job('cron', hour=16)
def timed_job_one():
print "16"
print ctime()
@sched.scheduled_job('cron', hour=17)
def timed_job_one():
print "17"
print ctime()
@sched.scheduled_job('cron', hour=9)
def timed_job_two():
print ctime()
print '9'
@sched.scheduled_job('cron', hour=11)
def timed_job_two():
print ctime()
print '11'
sched.start()
Run Code Online (Sandbox Code Playgroud)
它工作,但重复四次代码似乎很愚蠢,所以我的问题是如何使代码简短设置功能运行在每天9:00,11:00,16:00,17:00?
当文档明确说明如何正确执行此操作时,您为什么要单独安排作业四次?
@sched.scheduled_job('cron', hour='9,11,16,17')
def timed_job():
print ctime()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2815 次 |
| 最近记录: |