Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask restart / shutdown callback

Tags:

python

flask

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)

like image 917
Stephan Avatar asked Dec 05 '25 17:12

Stephan


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.

like image 195
davidism Avatar answered Dec 07 '25 07:12

davidism



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!