請教? 我是 Python 新手!
目前為了 Demo k8s 佈署,聆聽了視頻:
https://www.youtube.com/watch?v=Q6g7w7Cmwlk
其中所採用 python 所使用套件 Flask.
想知到如何在 python 內關掉 Flask.
一直試不出來? 能否請網友幫忙?
謝謝...
=========================================
from flask import Flask
import os
import socket
app = Flask(name)
@app.route("/")
def hello():
html = "<h3>Hello {name}!</h3>" \
"<b>Hostname:</b> {hostname}<br/>"
return html.format(name=os.getenv("NAME", "world"), hostname=os.getenv("HOST", socket.gethostname()))
@app.route("/crash")
def crash():
... 不知如何寫
if name == "main":
app.run(host='0.0.0.0', port=80)
想透過網頁 http://ip/crask 終止 Flask...
已經解決了,完整 Code 如下: 給有需要網友參考!...
=====================================
from flask import Flask
from flask import request
import os
import socket
app = Flask(name)
@app.route("/")
def hello():
html = "<h3>Hello {name}!</h3>" \
"<b>Hostname:</b> {hostname}<br/>"
return html.format(name=os.getenv("NAME", "world"), hostname=os.getenv("HOST", socket.gethostname()))
def shutdown_server():
func = request.environ.get('werkzeug.server.shutdown')
if func is None:
raise RuntimeError('Not running with the Werkzeug Server')
func()
@app.route("/crash", methods=['GET'])
def crash():
shutdown_server()