Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two Flask Applications at same time

Tags:

python

flask

I need to test two Flask Apps in my browser at the same time. By standard, Flask runs the app in the localhost:5000. So, a good alternative would be changing the address of one of the apps. Is that possible? If so, how to do it?

like image 546
Agnaldo Luiz Cunha Avatar asked Jun 30 '14 15:06

Agnaldo Luiz Cunha


People also ask

How do I connect two Flask apps?

Enter application dispatching. With this you can combine multiple Flask applications at the WSGI level. This also allows you to combine any WSGI application. So if you have separate Flask, Django, or Dash applications you can run them in the same interpreter side by side if you want.

Can Flask handle parallel requests?

Flask will process one request per thread at the same time. If you have 2 processes with 4 threads each, that's 8 concurrent requests. Flask doesn't spawn or manage threads or processes.

Is Flask API multithreaded?

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.

Why Flask should not be used in production?

Although Flask has a built-in web server, as we all know, it's not suitable for production and needs to be put behind a real web server able to communicate with Flask through a WSGI protocol. A common choice for that is Gunicorn—a Python WSGI HTTP server. Serving static files and proxying request with Nginx.


2 Answers

You can set the addres and port for your app

app.run(host='0.0.0.0',port=12345)

As long as the port numbers don't clash you can run seperate instances of flask apps on the same computer

like image 101
Ashoka Lella Avatar answered Oct 30 '22 09:10

Ashoka Lella


Since version 0.11, flask run is the recommended method to start a development server. In your case, open a new terminal, then run the same app on different port:

$ export FLASK_APP=my_app2  # use "set FLASK_APP=my_app2" on Windows
$ flask run --port 5001
like image 33
Grey Li Avatar answered Oct 30 '22 10:10

Grey Li