相关文章推荐
腼腆的柠檬  ·  python ...·  2 周前    · 
有情有义的大白菜  ·  python ...·  2 周前    · 
完美的馒头  ·  python QTreeWidget ...·  2 周前    · 
失眠的烤红薯  ·  python qt textBrowser ...·  2 周前    · 
空虚的南瓜  ·  java - Split string ...·  1 年前    · 
老实的草稿本  ·  1 - 进程 - Windows 10 - ...·  1 年前    · 
彷徨的大蒜  ·  HSV ...·  1 年前    · 
路过的酱肘子  ·  Windows + QtDesigner ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a simple BackgroundScheduler and a simple task. The BackgroundScheduler is configured to run only a single instance for that task:

from apscheduler.schedulers.background import BackgroundScheduler
scheduler.add_job(run_task, 'interval', seconds=10)
scheduler.start()

When a tasks starts, it takes much more than 10 seconds to complete and I get the warning:

Execution of job "run_tasks (trigger: interval[0:00:10], next run at: 2020-06-17 18:25:32 BST)" skipped: maximum number of running instances reached (1)

This works as expected.

My problem is that I can't find a way to check if an instance of that task is currently running.

In the docs, there are many ways to get all and individual scheduled tasks, but I can't find a way to check if a task is currently running or not. I would ideally want something like:

def job_in_progress():
    job = scheduler.get_job(id=job_id)
    instances = job.get_instances()
    return instances > 0

Any ideas?

Not great because you have to access a private attribute, but the only thing I could find.

def job_in_progress():
    job = scheduler.get_job(id=job_id)
    instances = scheduler._instances[job_id]
    return instances > 0

If someone else has another idea, don't use this.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.