Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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')
Comment

how to close a flask web server with python

from multiprocessing import Process

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

PREVIOUS NEXT
Code Example
Python :: 3 dimensional array in numpy 
Python :: como comentar en Python? 
Python :: streamlit button 
Python :: python cast list to float 
Python :: python code to exe file 
Python :: binary, decimal, hex conversion python 
Python :: find the difference in python 
Python :: python get the last element from the list 
Python :: check if there are duplicates in list 
Python :: data structures and algorithms in python 
Python :: boto3 client python 
Python :: sciket learn imputer code 
Python :: Python datetime to string using strftime() 
Python :: python find equal rows of two numpy arrays 
Python :: seaborn histplot modify legend 
Python :: try python import 
Python :: python get function name 
Python :: pandas check match string lowercase 
Python :: python bit shift by 3 
Python :: install python in docker file 
Python :: python plot groupby colors 
Python :: what is the difference between python 2 and 3 
Python :: queue python 
Python :: two dimensional array python 
Python :: python read json file array 
Python :: sort dictionary by value and then key python 
Python :: python - count total numeber of row in a dataframe 
Python :: python run command 
Python :: split python strings into pairs & complete uneven pairs 
Python :: numpy array split 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =