如何使用uwsgi + flask_apscheduler

时间:2017-05-29 23:04:41

标签: python flask uwsgi apscheduler

在Flask的本地开发服务器下运行时,会添加并正常运行作业。在uWSGI下运行时,作业似乎已添加到作业存储但从未执行。下面给出了一个描述了不良行为的简单例子:

__初始化__。PY

import flask
from datetime import datetime, timedelta
from flask_apscheduler import APScheduler

app = flask.Flask("apscheduler_test")
app.config["SCHEDULER_API_ENABLED"] = True
scheduler = APScheduler()
scheduler.init_app(app)
scheduler.start()

def test_job():
    print("test job run")

@app.route("/test")
def apscheduler_test():
    print("Adding Job")
    scheduler.add_job(id="101",
                      func=test_job,
                      next_run_time=(datetime.now() + timedelta(seconds=10)))
    return "view", 200

if __name__ == '__main__':
    app.run(port=5050)

apschedule_test.ini

[uwsgi]
pidfile = /var/run/%n.pid
chdir = /opt/apscheduler
master = true
enable-threads = true
threads = 20
http-socket = :48197
logto = /var/log/%n.log
plugin = python3
module = %n
callable = app
processes = 1
uid = root
gid = root
daemonize = /var/log/apscheduler_test.log

1 个答案:

答案 0 :(得分:0)

尝试将此标记添加到您的ini文件中:

lazy-apps=true

类似问题:uWSGI lazy-apps and ThreadPool