Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask seems to launch 2 instances of python [duplicate]

Tags:

python

flask

I have several Flask applications, but they all seem to launch 2 instances of Python. I have no idea why.

Edit: I have googled for Flask and multiple instances of Python, etc, but not one of my searches led me to the 'already answered question' here. I find my question much more to the point than: "Why does running the Flask dev server runs itself twice?" Huh? What is the Flask dev server? Does it have anything to do with Python running twice?

like image 687
zappfinger Avatar asked Sep 03 '25 15:09

zappfinger


1 Answers

It happens because you run your Flask applications in debug mode:

app.run(host='0.0.0.0', debug=True)

Debug mode automatically reloads the source files when they change. This is implemented so that Flask (actually, Werkzeug, a library used by Flask) spawns another Python interpreter, which monitors the source files and restarts the other interpreter that is running your Flask app.

If you set debug=False, you should get only one instance of Python per Flask app.

like image 182
Miikka Avatar answered Sep 05 '25 08:09

Miikka