Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I would like to use APScheduler to handle task scheduling and queues. I am currently using the very basic APScheduler settings: BackgroundScheduler() I know how to start the scheduler and set some cron on interval trigger job. But I can't figure out how to handle a proper queue.

Here is my code:

from apscheduler.schedulers.background import BackgroundScheduler


scheduler = BackgroundScheduler()

def test():
    print("Hello World !")

def start_job():
    scheduler.add_job(
        test
    )

start_job() # first task
start_job() # second task
start_job() # third task

scheduler.start()

This code kind of works but I need my tasks to run one after one and not all at the same time.

I've tried using the max_instances attribute but it doesn't change anything.

I've also tried to add an id to my job and then only the first task is started but not the left ones giving these warning: Execution of job "test (trigger: date[2021-01-12 17:55:48 UTC], next run at: 2021-01-12 17:55:48 UTC)" skipped: maximum number of running instances reached (1)

How am I supposed to start the left tasks ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
4.4k views
Welcome To Ask or Share your Answers For Others

1 Answer

The executor you choose determines how the jobs are executed – whether in parallel or in a sequence. If you don't want any parallelism, you can use a ThreadPoolExecutor with max_workers=1 to run them.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...