每5秒钟安排一次功能,如果函数花费的时间超过5秒钟,它将跳过作业。如何处理作业的跳过并等待时间表,直到上一个作业完成执行。
代码:
from apscheduler.schedulers.blocking import BlockingScheduler
sched = BlockingScheduler()
@sched.scheduled_job('interval', id='my_job_id', seconds=5)
def my_interval_job():
print 'Hello World!'
sched.start()
答案 0 :(得分:0)
你试过 simple_scheduler 吗?请查看here。
from time import sleep
from simple_scheduler.recurring import recurring_scheduler
def wait(t):
sleep(t)
print(f"I waited {t} seconds!")
recurring_scheduler.add_job(target=wait,
kwargs={"t":10}, # make it wait for 10 secs
period_in_seconds=5) # but call every 5 secs
recurring_scheduler.run()