【问题标题】:Issue while adding a job in APScheduler(Python 3.6)在 APScheduler(Python 3.6)中添加作业时出现问题
【发布时间】:2018-06-07 13:41:44
【问题描述】:

我正在尝试使用 APScheduler 每周安排一次我的 python 脚本 (merchant.py)

为此,我已经安装了该软件包,并且当我使用 cronjob 选项运行以下示例代码时-

from datetime import datetime
import time
import os
from apscheduler.schedulers.background import BackgroundScheduler
def tick():
print('Tick! The time is: %s' % datetime.now())

if __name__ == '__main__':
    scheduler = BackgroundScheduler()
    scheduler.add_job(tick, 'cron', day_of_week = 'mon', hour = 11)
    scheduler.start()
    print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
    try:
        while True:
            time.sleep(2)
    except (KeyboardInterrupt, SystemExit):
        scheduler.shutdown()

我收到以下错误-

KeyError: 'cron'

LookupError: 找不到名为“cron”的触发器

你能纠正我在这里做错了什么吗?

【问题讨论】:

    标签: python-3.6 apscheduler


    【解决方案1】:

    我找到了一种解决方案,因此可以分享给其他人-

    from apscheduler.schedulers.blocking import BlockingScheduler
    from apscheduler.triggers.combining import OrTrigger
    from apscheduler.triggers.cron import CronTrigger
    import time
    
    sched = BlockingScheduler()
    
    trigger = OrTrigger([
       CronTrigger(day_of_week='thu', hour='07', minute='28')
    ])
    sched.add_job(YOUR_JOB, trigger)
    sched.start()
    try:
        while True:
        time.sleep(2)
    except (KeyboardInterrupt, SystemExit):
        sched.shutdown()
    

    【讨论】:

      猜你喜欢
      • 2017-05-16
      • 1970-01-01
      • 2013-10-03
      • 2015-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多