python apscheduler - skipped: maximum number of ru

2019-04-23 02:56发布

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?

4条回答
孤傲高冷的网名
2楼-- · 2019-04-23 03:42

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.

查看更多
We Are One
3楼-- · 2019-04-23 03:44

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.

查看更多
相关推荐>>
4楼-- · 2019-04-23 03:50

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.

查看更多
【Aperson】
5楼-- · 2019-04-23 03:54

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.

查看更多
登录 后发表回答