python烧瓶调度:所有工人启动调度程序任务

问题描述 投票:0回答:1

我在烧瓶应用程序中使用预定任务:

    import time
    import atexit

    from apscheduler.schedulers.background import BackgroundScheduler


    def intervall():
        with app.app_context():
            call_function_to_do()

    scheduler = BackgroundScheduler()
    scheduler.add_job(func=intervall, trigger="interval", seconds=5)
    scheduler.start()

    # Shut down the scheduler when exiting the app
    atexit.register(lambda: scheduler.shutdown())

我的问题是所有的gunicorn工作者都在启动调度程序任务。在这种情况下,检查超时情况并向用户发送电子邮件。

有没有人知道如何让一个工人执行qazxsw poi?

python flask apscheduler
1个回答
0
投票

基本上有两种选择。 call_function_to_do()中概述的其中一个是将调度程序分离为单独的进程,并使用某些远程访问协议(例如使用FAQ)与进程通信。另一种方法是在Flask app中启动调度程序,但确保只运行一个这样的实例。您可以使用某种锁定机制,例如RPyC

© www.soinside.com 2019 - 2024. All rights reserved.