M. Lagadec
M. Lagadec

Reputation: 61

Flask auto-reload functionality not working with Pycharm Remote Deployment

It's hard to remember when, but at one point the auto-reload function of Flask started to not work anymore in my project. This is the output upon starting my app :

FLASK_APP = back/python/app/app.py:app
FLASK_ENV = development
FLASK_DEBUG = 1
In folder C:/path/to/project
ssh://[VirtualMachineIP]:22/root/env/bin/python3.7 -u -m flask run -h 0.0.0.0 -p 1234
 * Serving Flask app 'back/python/app/app.py:app' (lazy loading)
 * Environment: development
 * Debug mode: on
 * Running on all addresses.
   WARNING: This is a development server. Do not use it in a production deployment.
 * Running on http://[VirtualMachineIP]:1234/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 106-048-128

The development environment and Debug mode are both on. Thus, upon saving changes in a file (while the app is deployed) I get the usual message :

 * Detected change in '/path/to/changed/file.py', reloading

Signaling that the app is reloading with the new code. Except it doesn't reload anything, and the message doesn't appear on any further changes until I'm forced to restart the app.

PyCharms runs on Windows and communicates via ssh to my Virtual Machine, where the code is executed. I have installed the following modules:

Any help is welcomed. Thanks :)

Upvotes: 6

Views: 486

Answers (1)

NicoNing
NicoNing

Reputation: 3242

The FLASK_DEBUG environment variable is badly supported, it may not behave as expected if set in code. (Quoted from the source of flask).

It suggest to use flask run in debug mode.

eg: $ flask --app hello --debug run

If it still not work, you can force to use reloader like this:

if __name__ == '__main__':
    app.run(host=config.HOST, port=config.PORT, debug=True)

Take care, the app.run() must be wrapped with if __name__ == '__main__'.

doc: https://flask.palletsprojects.com/en/2.2.x/config/#DEBUG

Upvotes: 1

Related Questions