Issue running multiple interval jobs

294 views
Skip to first unread message

Brad Ahlers

unread,
Sep 9, 2015, 3:04:02 PM9/9/15
to APScheduler

I'm attempting to run multiple AP Scheduler jobs in my program (both interval and cron) but when I add multiple interval jobs with different intervals they all execute at the shortest interval. For example, I add one job with a frequency of 30 seconds and one with 15 seconds, both will execute every 15 seconds.

My code is below. How do I properly run these two jobs on separate intervals?


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", daemon=True))

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))


Alex Grönholm

unread,
Sep 9, 2015, 3:14:44 PM9/9/15
to apsch...@googlegroups.com
Can you provide example code that reproduces the problem? The code below is not exactly a standalone script. By the way, you can use the "args" parameter to pass arguments instead of having to write a lambda.
--
You received this message because you are subscribed to the Google Groups "APScheduler" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brad Ahlers

unread,
Sep 9, 2015, 9:07:26 PM9/9/15
to APScheduler
I actually added the "args" parameter and removed the lambda and this resolved my issue. It seems like using lambda caused some unexpected behavior during scheduled executions.


sched.add_job(module.handle, 'interval', args=[self.profile, mic], id=module.__name__, seconds=15)
sched.add_job(module2.handle, 'interval', args=[self.profile, mic], id=module2.__name__, seconds=30)
Reply all
Reply to author
Forward
0 new messages