Issue
I am implementing several flask apps which will all run on the same server. I am concerned about the recommended way of shutting down simple flask servers not working properly when more than one is running. The shutdown method from this snippet is:
from flask import request
def shutdown_server():
func = request.environ.get('werkzeug.server.shutdown')
if func is None:
raise RuntimeError('Not running with the Werkzeug Server')
func()
I do not see where the func()
method is defined so maybe I am missing something obvious but how will the shutdown method know which of the servers to shutdown? I would like to pass some kind of a parameter which would specify the server. Any ideas?
Solution
The app only interacts with the server serving it. It doesn't know about other servers running elsewhere. request.environ('werkzeug.server.shutdown')
points to a function that shuts down the server handling the request.
While the Werkzeug dev server happens to have the above hack that allows shutting down the server, it is not standard to WSGI servers. The dev server should never be used in production. There is no standard way to shut down a WSGI application (Flask in this case) from within the application. There should never be a reason to do this anyway.
As of Werkzeug 2.0, werkzeug.server.shutdown
is deprecated and will be removed in Werkzeug 2.1. See wait for value then stop server, after 'werkzeug.server.shutdown' is deprecated and removed for alternatives.
Answered By - davidism
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.