Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23276

How to shutdown Flask server and restart it with a different IP from the same Python script?

$
0
0

Here is the Flask setup for the problem.

import threadingfrom flask import Flask, requestapp = Flask(__name__)@app.route('/')def hello():    return 'Hello, World!'@app.route('/restart', methods=['GET'])def restart():    shutdown() # How do I shutdown the Flask server?    flask_thread.join()    flask_thread = threading.Thread(target=start_flask, args=(new_IP,))    flask_thread.start()    return 'Hello again, World!'def start_flask(ip):    app.run(host=ip)old_IP = '123.123.123.123'new_IP = '234.234.234.234'flask_thread = threading.Thread(target=start_flask, args=(old_IP,))flask_thread.start()

How do I shutdown the Flask server, and restart it with a different IP?


Viewing all articles
Browse latest Browse all 23276

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>