kms
kms

Reputation: 2024

Heroku deploy error : gunicorn.errors.HaltServer: <HaltServer 'App failed to load.' 4>

I am attempting to deploy flask app built using plotly-dash framework. However, I run into an gunicorn.errors.HaltServer.

app.py
index.py
- assets
- tabs
-- tab1
-- tab2

Procfile:

web: gunicorn index:app (also tried, web: gunicorn index:server and app:server)

index.py contains the following code to run the app:

if __name__ == '__main__':
    app.run_server(debug=True)

app.py includes:

import dash
import flask
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc


server = flask.Flask(__name__)
#app = dash.Dash(__name__, server=server)

app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])

app.config.suppress_callback_exceptions = True

To deploy locally, I run python index.py which works fine. However, I am not too sure about deploying multi-tab app to heroku.

Traceback:

2020-06-07T19:04:31.148521+00:00 heroku[web.1]: State changed from up to starting
2020-06-07T19:04:32.733304+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-06-07T19:04:32.782387+00:00 app[web.1]: [2020-06-07 19:04:32 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-06-07T19:04:32.782606+00:00 app[web.1]: [2020-06-07 19:04:32 +0000] [4] [INFO] Handling signal: term
2020-06-07T19:04:32.783987+00:00 app[web.1]: [2020-06-07 19:04:32 +0000] [11] [INFO] Worker exiting (pid: 11)
2020-06-07T19:04:32.984167+00:00 app[web.1]: [2020-06-07 19:04:32 +0000] [4] [INFO] Shutting down: Master
2020-06-07T19:04:33.100057+00:00 heroku[web.1]: Process exited with status 0
2020-06-07T19:04:43.276350+00:00 heroku[web.1]: Starting process with command `gunicorn index:server`
2020-06-07T19:04:45.969485+00:00 app[web.1]: [2020-06-07 19:04:45 +0000] [4] [INFO] Starting gunicorn 19.9.0
2020-06-07T19:04:45.970465+00:00 app[web.1]: [2020-06-07 19:04:45 +0000] [4] [INFO] Listening at: http://0.0.0.0:36003 (4)
2020-06-07T19:04:45.970600+00:00 app[web.1]: [2020-06-07 19:04:45 +0000] [4] [INFO] Using worker: sync
2020-06-07T19:04:45.976630+00:00 app[web.1]: [2020-06-07 19:04:45 +0000] [10] [INFO] Booting worker with pid: 10
2020-06-07T19:04:46.025840+00:00 app[web.1]: [2020-06-07 19:04:46 +0000] [11] [INFO] Booting worker with pid: 11
2020-06-07T19:04:46.386303+00:00 heroku[web.1]: State changed from starting to up
2020-06-07T19:04:55.000000+00:00 app[api]: Build succeeded
2020-06-07T19:04:57.395895+00:00 app[web.1]: Failed to find application object 'server' in 'index'
2020-06-07T19:04:57.396485+00:00 app[web.1]: [2020-06-07 19:04:57 +0000] [11] [INFO] Worker exiting (pid: 11)
2020-06-07T19:04:57.443947+00:00 app[web.1]: Failed to find application object 'server' in 'index'
2020-06-07T19:04:57.445193+00:00 app[web.1]: [2020-06-07 19:04:57 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-06-07T19:04:57.840352+00:00 app[web.1]: [2020-06-07 19:04:57 +0000] [4] [INFO] Shutting down: Master
2020-06-07T19:04:57.840598+00:00 app[web.1]: [2020-06-07 19:04:57 +0000] [4] [INFO] Reason: App failed to load.
2020-06-07T19:04:57.900650+00:00 heroku[web.1]: Process exited with status 4
2020-06-07T19:04:57.935000+00:00 heroku[web.1]: State changed from up to crashed
2020-06-07T19:04:57.937954+00:00 heroku[web.1]: State changed from crashed to starting
2020-06-07T19:05:08.770601+00:00 heroku[web.1]: Starting process with command `gunicorn index:server`
2020-06-07T19:05:10.916784+00:00 app[web.1]: [2020-06-07 19:05:10 +0000] [4] [INFO] Starting gunicorn 19.9.0
2020-06-07T19:05:10.917315+00:00 app[web.1]: [2020-06-07 19:05:10 +0000] [4] [INFO] Listening at: http://0.0.0.0:12394 (4)
2020-06-07T19:05:10.917416+00:00 app[web.1]: [2020-06-07 19:05:10 +0000] [4] [INFO] Using worker: sync
2020-06-07T19:05:10.921200+00:00 app[web.1]: [2020-06-07 19:05:10 +0000] [10] [INFO] Booting worker with pid: 10
2020-06-07T19:05:11.020805+00:00 app[web.1]: [2020-06-07 19:05:11 +0000] [18] [INFO] Booting worker with pid: 18
2020-06-07T19:05:11.572920+00:00 heroku[web.1]: State changed from starting to up
2020-06-07T19:05:20.160115+00:00 app[web.1]: Failed to find application object 'server' in 'index'
2020-06-07T19:05:20.160771+00:00 app[web.1]: [2020-06-07 19:05:20 +0000] [18] [INFO] Worker exiting (pid: 18)
2020-06-07T19:05:20.174812+00:00 app[web.1]: Failed to find application object 'server' in 'index'
2020-06-07T19:05:20.175384+00:00 app[web.1]: [2020-06-07 19:05:20 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-06-07T19:05:20.510412+00:00 app[web.1]: [2020-06-07 19:05:20 +0000] [4] [INFO] Shutting down: Master
2020-06-07T19:05:20.510517+00:00 app[web.1]: [2020-06-07 19:05:20 +0000] [4] [INFO] Reason: App failed to load.
2020-06-07T19:05:20.563920+00:00 heroku[web.1]: Process exited with status 4
2020-06-07T19:05:20.592058+00:00 heroku[web.1]: State changed from up to crashed
2020-06-07T19:08:28.283874+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=stroom-cre-platform.herokuapp.com request_id=2f63ecb5-808b-4583-bb18-7d2ee6b31a5f fwd="103.90.69.217" dyno= connect= service= status=503 bytes= protocol=https

Upvotes: 4

Views: 6962

Answers (1)

emher
emher

Reputation: 6024

You must pass the flask server to the dash app, i.e.

server = flask.Flask(__name__)
app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP], server=server)

Assuming this code is inside index.py, your profile should be along the lines of,

web: gunicorn index:server

Upvotes: 4

Related Questions