Esta es una vieja pregunta, pero buscar en Google no me dio ninguna idea de cómo lograrlo.
¡Porque no leí el código aquí correctamente! (¡Doh!) Lo que hace es levantar un RuntimeErrorcuando no hay werkzeug.server.shutdownen el request.environ...
Entonces, ¿qué podemos hacer cuando no hay requestes plantear unaRuntimeError
def shutdown():
raise RuntimeError("Server going down")
y coger eso cuando app.run()regrese:
...
try:
app.run(host="0.0.0.0")
except RuntimeError, msg:
if str(msg) == "Server going down":
pass # or whatever you want to do when the server goes down
else:
# appropriate handling/logging of other runtime errors
# and so on
...
No es necesario que se envíe una solicitud.