Roberto Duarte
Roberto Duarte

Reputation: 21

Why my flask app can't handle more than one client?

I created a simple flask application that needs authentication to have access to the data.

When I run this application locally it works fine (accepts more than one client), however when I host the app on railway or heroku it can't handle more than one client.

Ex: when I access the URL on a computer and log in, if I access the URL on my cellphone (different netowrk) I get to have access to that account logged in.

I'm using the latest version of flask and using flask_login to manage authentication.

Does anyone have any idea why it's happening?

I've tried everything I found out on Internet, such as using

app.run(threaded=True)

I've also set the numbers of workers on gunicorn command for exemple

Does anyone have any idea why it's happening?

Upvotes: 0

Views: 289

Answers (2)

Roberto Duarte
Roberto Duarte

Reputation: 21

I've just solved it.

My gunicorn was in sync way and would handle only one request at a time.

So I had insert threads number on Procifle in order to it change worker_class from sync to Gthread

My Procfile afterall:

web: gunicorn --threads 4 :$PORT index:app

https://docs.gunicorn.org/en/stable/design.html#choosing-a-worker-type

Upvotes: 1

akdev
akdev

Reputation: 606

As official Flask's documentation says, never run your application in production in dev mode (what app.run() actually is).

Please refer to this section if you are going to deploy in self-hosted machine: https://flask.palletsprojects.com/en/2.2.x/deploying/

And if you are going to deploy to Heroku, you need to prepare for correct Procfile, like this:

web: gunicorn run:app

Upvotes: 0

Related Questions