Python Apscheduler在有太多运行的作业时不一致

2024-10-04 05:31:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是一个使用python的调度程序apscheduler.scheduler,在我的项目中,有太多的作业在运行,但是机器的负载并不是太高,在看过文档之后,我找到了一个解决方案,我必须增加线程的大小,但是我不知道,如何增加线程 我的syntex:

scheduler.add_interval_job(triggerTask, interval_time, args=[], misfire_grace_time = None)

scheduler.add_cron_job(triggerTask, interval_time, args=[], misfire_grace_time = None)

Tags: 项目程序noneaddtimeargsjob调度
1条回答
网友
1楼 · 发布于 2024-10-04 05:31:36

由于您有90个任务要运行,您可能需要增加线程的数量,如果它们是计算敏感的,您还应该使用ProcessPoolExecutor

from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
from apscheduler.schedulers.background import BackgroundScheduler

executors = {
    'default': ThreadPoolExecutor(90),   # max threads: 90
    'processpool': ProcessPoolExecutor(20)  # max processes 20
}
scheduler = BackgroundScheduler(executors=executors) 

scheduler将使用defaultexecutor default,您可以通过scheduler.add_interval_job(triggerTask, interval_time, executor="<executor's name>")指定executor。在

相关问题 更多 >