Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Procfile for Python in Heroku?

I cannot seem to find a solid answer to this after scouring the web for answers. Currently, I have my directory set up this way:

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

So I not sure whether the Procfile is set up correctly...I have it set up this way:

web: gunicorn --pythonpath app runserver

However, when I run foreman start...heroku goes into a loop that keeps restarting the connection, I tried manually setting the port in the virtual environment export PORT=5001, but I am still getting the same error:

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)

Also, I have killed all gunicorn processes that are in used and tried running foreman start again...any ideas what could be going on?

Here is my runserver.py

from intro_to_flask import app

app.run(debug=True)
like image 225
ShaunK Avatar asked Feb 24 '26 02:02

ShaunK


1 Answers

When you run your app on gunicorn you do not use the same starter script that starts the development server. All gunicorn needs to know is from where to import the application. In your case I think what you want in your Procfile is something like this:

web: gunicorn --pythonpath app intro_to_flask:app

Not sure if this will work as is or if you will need to make minor tweaks. The idea is that you need to give gunicorn the package or module that defines the application, then a colon, and then the application instance symbol.

I hope this helps.

like image 139
Miguel Avatar answered Feb 27 '26 02:02

Miguel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!