代码之家  ›  专栏  ›  技术社区  ›  Anthr. Line

Gunicorn3进入开发服务器

  •  2
  • Anthr. Line  · 技术社区  · 2 年前

    当我用gunicorn为我的flask应用程序打开服务器时,它会自动打开flask的开发服务器,不会给我任何错误:

    $ gunicorn3 --workers=1 main:app
    \[2023-10-16 19:46:13 +0000\] \[1061\] \[INFO\] Starting gunicorn 20.1.0
    \[2023-10-16 19:46:13 +0000\] \[1061\] \[INFO\] Listening at: http://127.0.0.1:8000 (1061)
    \[2023-10-16 19:46:13 +0000\] \[1061\] \[INFO\] Using worker: sync
    \[2023-10-16 19:46:13 +0000\] \[1062\] \[INFO\] Booting worker with pid: 1062
    
    * Serving Flask app 'app'
    * Debug mode: off
      2023-10-16 19:46:14,209:INFO - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
    * Running on http://127.0.0.1:5000
      2023-10-16 19:46:14,209:INFO - Press CTRL+C to quit
    

    我已经有其他服务器使用gunicorn了,我不理解这种行为,有人知道吗?

    我已经更改了端口和主机,但结果是一样的,还有调试模式和gunicorn3的工作人员数量。

    1 回复  |  直到 2 年前
        1
  •  1
  •   Yuri R    2 年前

    如果您的主应用程序脚本中有以下行,那么它将导致Flask的开发服务器启动

    if __name__ == '__main__':
        app.run()
    
    • 你可以评论掉上面的部分
    • 确保您没有任何环境变量,例如 FLASK_ENV=development FLASK_APP=app.py
    • 确认 main:app 正确指向Flask应用程序对象
    推荐文章