Flask autoreload not reloading or picking up changes

Viewed 1710

I have an app.py flask application, that I want to enable auto-reloading for. This is the entry point:

APP = Flask(__name__)
APP.config.from_object(os.environ['APP_SETTINGS'])
# a lot of configurations ommited
if __name__ == "__main__":
    APP.run(debug=True, port=5005)

When I run the app, I get this in the terminal:

/Users/George/myproject/venv/bin/python /Users/George/myproject/app.py
 * Running on http://127.0.0.1:5005/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger pin code: 338-825-330

and when I modify one of my controllers it picks up that a change has occurred:

 * Detected change in '/Users/George/myproject/web_endpoints/user.py', reloading

but the change doesn't occur, and if I do another change, it never gets picked up (not reported in the terminal).

1 Answers

Flask is not recommended to use app.run() with automatic reloading as this is badly supported

Here's the comments in source code of Flask

def run(self, host=None, port=None, debug=None, load_dotenv=True, **options):

    """Runs the application on a local development server.
    ...        

    If you want to run the application in debug mode, but disable the
    code execution on the interactive debugger, you can pass
    ``use_evalex=False`` as parameter.  This will keep the debugger's
    traceback screen active, but disable code execution.


    It is not recommended to use this function for development with
    automatic reloading as this is badly supported.  Instead you should
    be using the :command:`flask` command line script's ``run`` support.

    ...  
    """
    pass      

But you can force to use reloader like this:

app.run(debug=True, use_reloader=True)
Related