Flask-SocketIO
Flask-SocketIO copied to clipboard
Clean shutdown for werkzeug
I have a (sightly unusual use case) running well. It needs to be a threaded application - but it's single user local interface for another project. I start the server using start_background_task() in which I run flask_SocketIO.SocketIO.run(app). I shutdown the server by sending an event which calls flask_SocketIO.SocketIO.stop(). This all works cleanly at exit.
However I learned from the debug logs, stop() looks for werkzeug's shutdown method - which is deprecated. Will the threaded / werkzeug shutdown mechanism be updated?
To answer my own question, it seems like the real issue is that you don't get a handle on the Base/ThreadedWSGIServer that is created inside run_simple in werkzeug, but if you do create your own, it's easy to set shutdown_signal = True on it.
My initial thoughts about this is that if Werkzeug does not provide a way to shutdown gracefully anymore then the stop() method is not going to work anymore with this web server. The pressure should be made on Werkzeug to provide an alternative way to shutdown, not on this package to build an alternative to run_simple which is completely out of scope.
I asked over at werkzeug https://github.com/pallets/werkzeug/issues/2284
My use case might be a little odd given I'm integrating a ux onto an existing project and it's goal isn't serving at scale. But generally it looks like you have to call make_server so you can get a handle on the http server which you can then use to stop it via its stop method. That's a little unfortunate as run_simple which socketio uses is obviously simpler.