【问题标题】:How to create a Procfile for Python in Heroku?如何在 Heroku 中为 Python 创建 Procfile?
【发布时间】:2014-02-23 05:08:46
【问题描述】:

在网上搜索答案后,我似乎无法找到可靠的答案。目前,我的目录是这样设置的:

flaskapp
     -app
        -intro_to_flask
              +__init__.py
              +config.py
              +routes.py
              +forms.py
        -runserver.py
        -Readme.md
     -bin
     -include
     -lib
     -view
Procfile
requirements.txt

所以我不确定Procfile 是否设置正确...我是这样设置的:

web: gunicorn --pythonpath app runserver

但是,当我运行 foreman start...heroku 进入一个不断重启连接的循环时,我尝试在虚拟环境 export PORT=5001 中手动设置端口,但我仍然收到相同的错误:

Running on http://127.0.0.1:5000/
12:21:20 web.1  |  * Restarting with reloader
12:21:20 web.1  | 2014-02-22 12:21:20 [34532] [INFO] Starting gunicorn 18.0
12:21:20 web.1  | 2014-02-22 12:21:20 [34532] [ERROR] Connection in use: ('0.0.0.0', 5001)

另外,我已经杀死了所有正在使用的 gunicorn 进程,并尝试再次运行 foreman start...有什么想法会发生什么吗?

这是我的runserver.py

from intro_to_flask import app

app.run(debug=True)

【问题讨论】:

  • 可以显示runserver.py的内容吗?
  • @Miguel Sure...我的内容如下:

标签: python python-2.7 heroku flask


【解决方案1】:

当您在 gunicorn 上运行应用程序时,您不会使用启动开发服务器的相同启动脚本。所有 gunicorn 需要知道的是从哪里导入应用程序。在您的情况下,我认为您在 Procfile 中想要的是这样的:

web: gunicorn --pythonpath app intro_to_flask:app

不确定这是否会按原样工作,或者您是否需要进行微调。这个想法是你需要给gunicorn定义应用程序的包或模块,然后是一个冒号,然后是应用程序实例符号。

我希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-29
    • 2017-07-01
    • 1970-01-01
    • 2019-03-13
    • 1970-01-01
    • 2020-02-12
    • 2016-12-15
    相关资源
    最近更新 更多