Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Threaded=true Flask larger application file structure

Tags:

python

flask

I recently created a web app and used the suggested file structuring from flask for separating views in different files. see here, http://flask.pocoo.org/docs/0.12/patterns/packages/.

But I also need to have the threaded parameter set to true which I would usually do at app.run(threaded=True) stage of testing. But I now run the app a different way, i tried putting "threaded=True" into my setup.py and that didn't do anything and was wondering how to get this working.

like image 840
jason translol Avatar asked Mar 10 '17 03:03

jason translol


People also ask

What is threaded true in flask?

With threaded=True requests are each handled in a new thread. How many threads your server can handle concurrently depends entirely on your OS and what limits it sets on the number of threads per process. The implementation uses the SocketServer.

Are flasks multi threaded?

As of Flask 1.0, flask server is multi-threaded by default. Each new request is handled in a new thread. This is a simple Flask application using default settings.


1 Answers

Just tell the flask run command to use threads:

$ export FLASK_APP=yourapplication
$ flask run --with-threads

Don't put this decision in your code; it is up to your WSGI server to run with threads or not.

You can see what options flask run accepts with flask run --help.

like image 71
Martijn Pieters Avatar answered Oct 08 '22 10:10

Martijn Pieters