“Hentikan server Flask” Kode Jawaban

cara menutup server web flask dengan python

from flask import Flask, request, jsonify

# Workaround - otherwise doesn't work in windows service.
cli = sys.modules['flask.cli']
cli.show_server_banner = lambda *x: None

app = Flask('MyService')

# ... business logic endpoints are skipped.

@app.route("/shutdown", methods=['GET'])
def shutdown():
    shutdown_func = request.environ.get('werkzeug.server.shutdown')
    if shutdown_func is None:
        raise RuntimeError('Not running werkzeug')
    shutdown_func()
    return "Shutting down..."


def start():
    app.run(host='0.0.0.0', threaded=True, port=5001)


def stop():
    import requests
    resp = requests.get('http://localhost:5001/shutdown')
Gentle Gerbil

cara menutup server web flask dengan python

from multiprocessing import Process

server = Process(target=app.run)
server.start()
# ...
server.terminate()
server.join()
Gentle Gerbil

Python cara memulai ulang labu secara otomatis

app.run(debug=True)
loneWolf_sage

Shutdown Flask Server dengan permintaan

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()

@app.route('/shutdown', methods=['POST'])
def shutdown():
    shutdown_server()
    return 'Server shutting down...'
Puzzled Puffin

Hentikan server Flask

@app.route("/shutdown", methods=['GET'])
def shutdown():
    shutdown_func = request.environ.get('werkzeug.server.shutdown')
    if shutdown_func is None:
        raise RuntimeError('Not running werkzeug')
    shutdown_func()
    return "Shutting down..."
SMR

Jawaban yang mirip dengan “Hentikan server Flask”

Pertanyaan yang mirip dengan “Hentikan server Flask”

Lebih banyak jawaban terkait untuk “Hentikan server Flask” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya