Answers for "how to close a flask web server with python"

0

how to close a flask web server with 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')
Posted by: Guest on April-02-2021
0

how to close a flask web server with python

from multiprocessing import Process

server = Process(target=app.run)
server.start()
# ...
server.terminate()
server.join()
Posted by: Guest on April-02-2021

Python Answers by Framework

Browse Popular Code Answers by Language