Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python apscheduler - skipped: maximum number of running instances reached

I am executing a function every second using Python apscheduler (version 3.0.1)

code:

scheduler = BackgroundScheduler()
scheduler.add_job(runsync, 'interval', seconds=1)
scheduler.start()

It's working fine most of the time but sometimes I get this warning:

WARNING:apscheduler.scheduler:Execution of job "runsync (trigger: interval[0:00:01], next run at: 2015-12-01 11:50:42 UTC)" skipped: maximum number of running instances reached (1)

1.Is this the correct way to execute this method?

2.What does this warning mean? Does it affect the execution of tasks inside the function in anyway?

3.how to handle this?

like image 433
boyfromnorth Avatar asked Dec 01 '15 12:12

boyfromnorth


4 Answers

It means that the task is taking longer than one second and by default only one concurrent execution is allowed for a given job. I cannot tell you how to handle this without knowing what the task is about.

like image 136
Alex Grönholm Avatar answered Nov 06 '22 20:11

Alex Grönholm


Increase max_instances

If the particular use case permits it, simply increase max_instances as shown below.

import apscheduler.schedulers.background

scheduler = apscheduler.schedulers.background.BackgroundScheduler({'apscheduler.job_defaults.max_instances': 2})

There are three apscheduler configuring styles. These are described in the documentation. Above is the dictionary/JSON style, here is the argument style:

import apscheduler.schedulers.background

scheduler = apscheduler.schedulers.background.BackgroundScheduler(job_defaults={'max_instances': 2})
like image 24
Serge Stroobandt Avatar answered Nov 06 '22 18:11

Serge Stroobandt


If you want concurrently running instances of the same job and avoid the warning, you can include the max_instances argument in the scheduler's add_job() method. The default value is one.

like image 9
Jorge Luis Avatar answered Nov 06 '22 19:11

Jorge Luis


I am pretty sure my task is not taking more than the interval. I just followed this answer instead and switched to apscheduler==2.1.2 as suggested here.

like image 1
Semih Sezer Avatar answered Nov 06 '22 19:11

Semih Sezer