Black Lives Matter. Please consider donating to Black Girls Code today.

Development lifecycle and termination on error

Hi everyone,

Dash new starter here. I am wanting to set up an efficient development lifecycle between IDE and browser.

The recommended development environment is to use python This has the benefit of hot reloading of both code and auto-refresh in the browser.

The one issue I am experiencing is that if an exception is raised in the python code, the server immediately terminates. This means having to restart the server by going back to the command line until the error is fixed, and impacts productivity.

Most web servers would raise an exception but not terminate.

If there is a way to prevent this from happening that would be great—either through a change to the embedded Flask server or by configuring a new Flask app altogether.

I tried using gunicorn app:server however, it does not reload the python code until it is restarted.

Any help would be much appreciated.



One trick that we do sometimes is this:

$ while true; do python; sleep 1; done

Thank you for this. I don’t really understand though why this does not function as a “normal” Flask application, which will show the error in the browser and keep the serving process alive, rather than exiting completely. Have tried mounting it in a separate Flask application, but then seem to lose the nifty browser live-reload etc.