I have the following code for Flask + Waitress + Webtest:
from flask import Flask from webtest import http app = Flask(__name__) HOST = "0.0.0.0" PORT = 9000 THREADS = 20 SERVER = None @app.route("/shutdown", methods=["GET"]) def shutdown(): SERVER.shutdown() return "Moo" def main(): global SERVER # this extends waitress SERVER = http.StopableWSGIServer(app, host=HOST, port=PORT, threads=THREADS) SERVER.run() if __name__ == "__main__": main()
The purpose of this code is when you request
/shutdown, that the whole server shutsdown/terminates.
Is something like this possible with Sanic? If so, what is the most Sanoc-idiomatic way to achieve this?
The reason I’d like to move to Sanic (over Waitress) is the ability to use multiprocessing, so in terminating one worker, I’d like terminate the whole Sanic server (and therefore all other workers as well).
For some context: I’m very interested in using
fast=True (but could also hard-code the number of workers) and I’d also like to be able to use this on Windows.