Handling multiple requests in Flask

2019-01-03 05:41发布

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.

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

标签: python flask
2条回答
闹够了就滚
2楼-- · 2019-01-03 06:28

For requests that take a long time, you might want to consider starting a background job for them.

查看更多
Summer. ? 凉城
3楼-- · 2019-01-03 06:33

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

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.

查看更多
登录 后发表回答