3

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?

zappfinger
  • 497
  • 2
  • 5
  • 15
  • 1
    What does this mean? What are you counting as "launching an instance of Python"? How do you tell? How are you serving the applications? – Daniel Roseman Jun 07 '15 at 10:45
  • I can see that in Activity Monitor (OS X) or by ps -ef|grep py. Also, in one of my programs I use: if __name__ == '__main__': print "starting Flask server" app.run(host='0.0.0.0', debug=True) This prints 'starting Flask server' twice! – zappfinger Jun 07 '15 at 11:56
  • I do not understand the down vote. This must be a very common problem, but after quite some searching I still could not find a decent answer... – zappfinger Jun 07 '15 at 13:50

1 Answers1

11

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.

Miikka
  • 4,573
  • 34
  • 47