What is the simplest way to reliably save data to a file when flask app.run() stops/crashes?
try:
app.run()
except Exception as e:
#<cleanup and save>
Does not work for sigint/ctrl+c etc they must be try/excepted in app.run()
signal.signal(signal.SIGINT, signal_handler)
app.run()
signal.pause()
works for ctrl+c (but not always)
@app.errorhandler(Exception)
def save_on_exit(error):
# <cleanup and save>
return response
works on error in views.
Is there a solution that just writes to the file on exit, or do I need all 3 of those?