Search code examples
pythonherokuquart

Using Quart in Heroku


Right now I'm trying to host a Quart web app on Heroku. Here is my test code:

#quartTest.py

from quart import Quart, request, Response

app = Quart(__name__)

@app.route('/')
def index():
    return 'hello world'

if __name__ == '__main__':
    app.run()

My Procfile is currently: web: hypercorn -b 0.0.0.0:5000 quartTest:app

This is my error: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

Here are some logs, it will repeat forever:

2021-04-20T03:19:38.541174+00:00 heroku[web.1]: State changed from crashed to starting
2021-04-20T03:19:42.507344+00:00 heroku[web.1]: Starting process with command `hypercorn -b 0.0.0.0:5000 quartTest:app`
2021-04-20T03:19:46.446529+00:00 app[web.1]: [2021-04-20 03:19:46 +0000] [4] [INFO] Running on http://0.0.0.0:5000 (CTRL + C to quit)
2021-04-20T03:19:47.000000+00:00 app[api]: Build succeeded
2021-04-20T03:20:42.755100+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2021-04-20T03:20:42.932268+00:00 heroku[web.1]: Stopping process with SIGKILL
2021-04-20T03:20:43.043982+00:00 heroku[web.1]: Process exited with status 137
2021-04-20T03:20:43.111245+00:00 heroku[web.1]: State changed from starting to crashed
2021-04-20T03:20:43.115104+00:00 heroku[web.1]: State changed from crashed to starting
2021-04-20T03:20:47.727102+00:00 heroku[web.1]: Starting process with command `hypercorn -b 0.0.0.0:5000 quartTest:app`
2021-04-20T03:20:52.904681+00:00 app[web.1]: [2021-04-20 03:20:52 +0000] [4] [INFO] Running on http://0.0.0.0:5000 (CTRL + C to quit)

If anyone can help me, I'd be grateful.


Solution

  • Set Procfile to web hypercorn -b 0.0.0.0:$PORT quartTest:app

    If you're running a discord bot you'll have to change

    bot.loop.create_task(app.run_task())

    to

    bot.loop.create_task(api.app.run_task(host='0.0.0.0', port=PORT))