我有一个用于Web和移动应用程序的服务器的Flask。但有时在负载过重的情况下,应用程序或网站会停止快速响应并显示需要时间的结果,I只是想在WSGIServer.运行的烧瓶中启用多线程。
def main():
"""Main entry point of the app."""
try:
http_server = WSGIServer(('0.0.0.0', 8084), app, log=logging, error_log=logging)
http_server.serve_forever()
except Exception as exc:
logger.error(exc.message)
logger.exception(traceback.format_exc())
finally:
# Do something here
pass谢谢,
发布于 2018-05-17 18:24:26
内置的Flask开发服务器虽然不适合多线程使用或部署,但确实允许多线程:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'Hello, world!'
if __name__ == '__main__':
app.run(threaded=True)上面的代码是一个简单的Hello脚本,它使用多线程;不是说任何进程都在使用另一个线程,但是您了解了这一点。
https://stackoverflow.com/questions/50365318
复制相似问题