在 Flask 中处理多个请求 [英] Handling multiple requests in Flask

查看:66
本文介绍了在 Flask 中处理多个请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Flask 应用程序必须进行大量计算才能获取某个页面.当 Flask 正在执行该功能时,另一个用户无法访问该网站,因为 Flask 正忙于进行大量计算.

My Flask applications has to do quite a large calculation to fetch a certain page. While Flask is doing that function, another user cannot access the website, because Flask is busy with the large calculation.

有什么方法可以让我的 Flask 应用程序接受来自多个用户的请求?

Is there any way that I can make my Flask application accept requests from multiple users?

推荐答案

是的,将您的应用程序部署在不同的 WSGI 服务器上,请参阅 Flask 部署选项文档.

Yes, deploy your application on a different WSGI server, see the Flask deployment options documentation.

Flask 附带的服务器组件实际上仅用于开发应用程序时;即使它可以配置为使用 app.run(threaded=True) 处理并发请求(从 Flask 1.0 开始,这是默认设置).上面的文档列出了可以处理并发请求的服务器的几个选项并且更加健壮和可调整.

The server component that comes with Flask is really only meant for when you are developing your application; even though it can be configured to handle concurrent requests with app.run(threaded=True) (as of Flask 1.0 this is the default). The above document lists several options for servers that can handle concurrent requests and are far more robust and tuneable.

这篇关于在 Flask 中处理多个请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆