65
votes

I've built a few Flask apps, but on my latest project I noticed something a little strange in development mode. The second line of the usual message in the terminal which always reads:

 * Running on http://127.0.0.1:5000/
 * Restarting with reloader

has been replaced by:

 * Restarting with stat

I don't think I've done anything different, in fact, I started by cloning a starter-kit project that I have used many times, which itself, does not display this behavior. I also notice that this project consumes about 15% CPU steadily, whereas my other project are barely a blip.

Any ideas why this is happening?

4
I can confirm that a) the behavior change seems to be a result of a change in the Werkzeug version. b) that the heightened resource usage seems to be associated with the reloader - setting debug = False changes the behavior. and c) that installing watchdog lowers the system resource requirements. I would also note that running an app in dev mode now results in two python interpreters running vs. previously when only one ran. (either with watchdog or without) Also: with watchdog installed, the message will be: Restarting with fsevents reloader - domoarigato
Thank you for this question. In my case, reloading did not work at all until I installed watchdog. - user67416
I just noticed this as well. Is it a bug that it does not print the "Running on http://..." message when debug=True ? I guess they figure if you're debugging then you know the localhost business... - Matthew Cornell
By any chance, were you using .run() in your code? I had this issue, but changed to using the export FLASK_APP=app.py via terminal. No longer an issue for me. Referenced here in the docs flask.pocoo.org/docs/0.11/quickstart/#a-minimal-application - JasTonAChair
I think the cli was not even available at the time of this question, actually. - domoarigato

4 Answers

57
votes

Check your version of Werkzeug. Version 0.10 was just released and numerous changes went into the reloader. One change is that a default polling reloader is used; the old pyinotify reloader was apparently inaccurate. If you want more efficient polling, install the watchdog package. You can see the code related to this here.

When Werkzeug can't find watchdog, it uses the stat reloader, otherwise it uses whatever reloader watchdog uses, which can vary by platform. This message is just so you know which one is in use.


Watchdog may not be compatible with gevent. If you're using gevent and having issues with the reloader when using Watchdog, check this GitHub issue.

40
votes

Use run(use_reloader=False) to disable the reloader.

It gave me some problems where it wasn't able to find my server file when it restarted. This did the trick. It executed just once and everything worked. Quite odd.

14
votes

If you run with app.run(debug=True), it will run the reloader as part of debug mode. If you don't want to use debug mode, pass debug=False or don't pass it at all.

-2
votes

my filename was __main__.py and I exported it as such: export FLASK_APP=__main__.py Upon changing the name to app.py and reexporting it, it worked.