Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python apscheduler not consistent when there are too many jobs running

I am using a scheduler using python apscheduler.scheduler, and In my project, there are too many jobs running, but the machine load wasn't too high, After go through the documentation, I came to the solution that, I have to increase the size of the thread , But I don't know, How to increase the thread My 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)
like image 436
Nitesh Avatar asked Jan 31 '26 05:01

Nitesh


1 Answers

As you have 90 tasks to run, you may need to increase the number of threads and if they are calculation sensitive, you should also use 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 will use default executor default, and you can specify executor by scheduler.add_interval_job(triggerTask, interval_time, executor="<executor's name>").

like image 96
Sraw Avatar answered Feb 02 '26 17:02

Sraw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!