onionshare
onionshare copied to clipboard
Figure out new way to shutdown flask service
When we stop an OnionShare service, this web.force_shutdown()
function is run:
def force_shutdown(self):
"""
Stop the flask web server, from the context of the flask app.
"""
# Shutdown the flask service
try:
func = request.environ.get("werkzeug.server.shutdown")
if func is None and self.mode != "chat":
raise RuntimeError("Not running with the Werkzeug Server")
func()
except Exception:
pass
self.running = False
# If chat, shutdown the socket server
if self.mode == "chat":
self.socketio.stop()
I noticed when running tests we get this warning:
/home/circleci/repo/cli/onionshare_cli/web/web.py:342: UserWarning: The 'environ['werkzeug.server.shutdown']' function is deprecated and will be removed in Werkzeug 2.1.
I looked into this, and they give their rationale for deprecating this here: https://github.com/pallets/werkzeug/issues/1752
Also, we should probably run Flask in production instead of dev.
~~Waitress might be interesting?~~ Nevermind, it works in principle, but it doesn't support gzip, so we are better off moving to Nginx I guess...