【问题标题】:Disable reloader of gunicorn flask application禁用 gunicorn 烧瓶应用程序的重新加载
【发布时间】:2020-10-26 15:22:10
【问题描述】:

当我在本地机器上运行烧瓶服务器时,我使用这个代码

app.run(host='0.0.0.0', port=port,debug=False,use_reloader=False)

我正在使用 BackgroundScheduler,所以我需要重新加载为 false 否则 BackgroundScheduler 将运行两次。

from apscheduler.schedulers.background import BackgroundScheduler

当我部署到 Heroku 时,我会像这样使用 gunicorn

web: gunicorn app:app

所以问题是使用这个时 reloader 是真的,所以 BackgroundScheduler 有两个实例。
那么如何停止 Gunicorn 的重新加载?
任何帮助将不胜感激。

如上图所示,创建了 2 个进程。
提前谢谢你

【问题讨论】:

    标签: python python-3.x flask heroku gunicorn


    【解决方案1】:

    你可以在 heroku 中提供与命令行参数相同的参数:

    web: gunicorn app:app --reload=False

    这确实为您的问题提供了答案,但它不会解决问题,因为--reload 的默认值已经是False。您可以使用gunicorn --help 进行检查。

    我认为你不应该使用BackgroundScheduler,而应该使用--daemon 标志。根据gunicorn --help -D, --daemon - Daemonize the Gunicorn process. [False]。 “To Daemonize”意味着将其作为后台进程运行。

    【讨论】:

    • 感谢您的帮助,我会调查此事。我为我的问题找到了另一个可行的解决方案,即使用对我有用的--preload
    猜你喜欢
    • 1970-01-01
    • 2012-11-19
    • 1970-01-01
    • 2011-08-10
    • 2020-05-23
    • 2016-04-01
    • 2014-04-11
    • 2013-04-07
    • 1970-01-01
    相关资源
    最近更新 更多