我试图在我的程序中运行多个AP调度程序作业(interval和cron),但是当我添加多个间隔不同的作业时,它们都以最短的间隔执行。例如,如果我添加一个频率为30秒的作业和一个频率为15秒的作业,这两个作业都将每15秒执行一次。在
我的代码在下面。如何在不同的时间间隔正确地运行这两个作业?在
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.executors.pool import ProcessPoolExecutor
executors = {
'default': {'type': 'threadpool', 'max_workers': 20},
'processpool': ProcessPoolExecutor(max_workers=5)
}
job_defaults = {
'coalesce': False,
'max_instances': 3
}
sched = BackgroundScheduler(executors=executors, job_defaults=job_defaults, timezone="EST")
sched.start()
sched.add_job(lambda: module.handle(self.profile, mic), 'interval', id=module.__name__, seconds=15)
sched.add_job(lambda: module2.handle(self.profile, mic), 'interval', id=module2.__name__, seconds=30)
atexit.register(lambda: sched.shutdown(wait=False))
你添加了2个工作
具有双重ID的
id=module.__name__
。您需要自己指定ID吗?Apscheduler可以为您完成。在这是我用的兰姆达的问题。我通过如下方式添加args参数来删除lambda。在
相关问题 更多 >
编程相关推荐