how to run flask in another thread in python

Solutions on MaxInterview for how to run flask in another thread in python by the best coders in the world

showing results for - "how to run flask in another thread in python"
Cheri
24 Sep 2017
1from flask import *
2from threading import Thread
3
4app = Flask(__name__)
5
6@app.route("/", methods=["POST", "GET"])
7def home():
8	return render_template("index.html")
9
10
11if __name__ == "__main__":
12	app.run(debug=True)
13
14#   Preparing parameters for flask to be given in the thread
15#   so that it doesn't collide with main thread
16	kwargs = {'host': '127.0.0.1', 'port': 5000, 'threaded': True, 'use_reloader': False, 'debug': False}
17
18#   running flask thread
19	flaskThread = Thread(target=app.run, daemon=True, kwargs=kwargs).start()