Flask restart / shutdown callback

Viewed 1254

I’m using Flask on a Raspberry Pi for an IoT application.

My problem is, that I need to cleanly close the connection to my external device before the application is shutdown or restarted by the Flask auto-reloader.

Is there any callback / handler / event / etc. I can use for a clean shutdown? (that also works with the auto-reloader)

1 Answers

Application shutdown is not part of the WSGI server standard. There is no general way to know when the server stops completely from within the application code.

Related