我使用APScheduler,现在有很多工作需要启动。我配置了next_run_time,但是没有用?

问题描述 投票:0回答:1

我想让我的工作现在就开始,我知道我可以用job.modify方法来改变next_run_time,但是很多工作需要编辑,所以我配置了调度器。

from datetime import datetime

import pytz
from apscheduler.schedulers.background import BackgroundScheduler

scheduler = BackgroundScheduler(next_run_time=datetime.now)

scheduler.configure(timezone=pytz.timezone('Asia/Shanghai'))


def test():
    print('hello', datetime.now())


job = scheduler.add_job(test, 'interval', seconds=30, id='my_job_id')

print(datetime.now())
scheduler.start()

作业现在没有运行,我该怎么办?

python apscheduler
1个回答
0
投票

你需要把当前时间传递给 scheduler.add_job():

scheduler.add_job(test, 'interval', seconds=30, id='my_job_id',
                  next_run_time=datetime.now())
© www.soinside.com 2019 - 2024. All rights reserved.