问题
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?
回答1:
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.
回答2:
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.
回答3:
If the particular use case permits it, simply increase max_instances
as shown below.
import apscheduler.schedulers.blocking
scheduler = apscheduler.schedulers.blocking.BackgroundScheduler('apscheduler.job_defaults.max_instances': '2')
There are three apscheduler
configuring styles. These are described in the documentation.
回答4:
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.
来源:https://stackoverflow.com/questions/34020161/python-apscheduler-skipped-maximum-number-of-running-instances-reached