[英]Disable reloader of gunicorn flask application
當我在本地機器上運行 flask 服務器時,我使用此代碼
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 個進程。
先感謝您
您可以在 heroku 中提供與命令行 arguments 相同的 arguments:
web: gunicorn app:app --reload=False
這確實為您的問題提供了答案,但它不會解決問題,因為--reload
的默認值已經是False
。 您可以使用gunicorn --help
進行檢查。
我認為您不應該使用BackgroundScheduler
,而應使用--daemon
標志。 根據gunicorn --help
: -D, --daemon - Daemonize the Gunicorn process. [False]
-D, --daemon - Daemonize the Gunicorn process. [False]
。 “To Daemonize”意味着將其作為后台進程運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.