0

I realized that APScheduler (3.3.1) with Python (2.7) only run a limited number of my jobs, so I made a test file to check it better, this is my code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import datetime
import time

from apscheduler.schedulers.background import BackgroundScheduler


def fetch_job(a):
    print a
    time.sleep(1)
    print a, ' awakened'


scheduler = BackgroundScheduler()

schedules = [
    {'source': '1', 'interval': 10, 'job': fetch_job},
    {'source': '2', 'interval': 10, 'job': fetch_job},
    {'source': '3', 'interval': 10, 'job': fetch_job},
    {'source': '4', 'interval': 10, 'job': fetch_job},
    {'source': '5', 'interval': 10, 'job': fetch_job},
    {'source': '6', 'interval': 10, 'job': fetch_job},
    {'source': '7', 'interval': 10, 'job': fetch_job},
    {'source': '8', 'interval': 10, 'job': fetch_job},
    {'source': '9', 'interval': 10, 'job': fetch_job},
    {'source': '10', 'interval': 10, 'priority': 3, 'job': fetch_job},
    {'source': '11', 'interval': 10, 'job': fetch_job},
    {'source': '12', 'interval': 10, 'job': fetch_job},
    {'source': '13', 'interval': 10, 'job': fetch_job},
    {'source': '14', 'interval': 10, 'job': fetch_job}
]
for i, k in enumerate(schedules):
    scheduler.add_job(k['job'], 'interval', seconds=k['interval'],
                      args=[k['source'],], next_run_time=datetime.datetime.now())

scheduler.start()
while True:
    time.sleep(2)

When i run it Output is like this:

1
2
3
4
5
6
7
8
9
10
1  awakened
No handlers could be found for logger "apscheduler.executors.default"
2  awakened
 43   awakened65
 awakened
  awakened
 awakened
7  awakened
8  awakened
9  awakened
10  awakened

In first run, only 10 jobs trigger, while I added 14 job to scheduler, but when scheduler trigger for second round and so on, I see other jobs too.

A.F.N
  • 199
  • 2
  • 15
  • So did you try following the troubleshooting instructions in the documentation? – Alex Grönholm Nov 20 '22 at 14:10
  • Thanks @AlexGrönholm for your comment. I added logging and it seems scheduler missing that jobs to trigger due `was missed by 0:00:01.004307` so I found your answer [here](https://stackoverflow.com/a/30258070/5468052) about reason for missing jobs, but honestly my processor (12 core) is not busy. – A.F.N Nov 21 '22 at 07:30
  • 1
    Try increasing `misfire_grace_time` from its default of 1 second. – Alex Grönholm Nov 22 '22 at 15:17

0 Answers0