python同时同步发送多个请求_python flask如何解决同时请求同一个请求的阻塞问题?...

本文介绍了如何利用gevent库来解决Python Flask应用中同时请求同一个接口时出现的阻塞问题。通过monkey.patch_all()对标准库进行补丁处理,然后创建WSGIServer,使得应用能够同时处理多个请求,提高了并发性能。
摘要由CSDN通过智能技术生成

可以用gevet啊

from gevent import monkey

from gevent.pywsgi import WSGIServer

monkey.patch_all()

from flask import Flask

import time

app = Flask(__name__)

@app.route('/test',methods=['GET'])

def sayHello():

time.sleep(10)

return 'hello'

@app.route('/hi',methods=['GET'])

def sayHi():

return 'hi'

if __name__ =='__main__':

http_server = WSGIServer(('', 5000), app)

http_server.serve_forever()

测试结果:

127.0.0.1 - - [2017-12-12 22:35:10] "GET /test/ HTTP/1.1" 200 126 0.000000

127.0.0.1 - - [2017-12-12 22:35:11] "GET /test/ HTTP/1.1" 200 126 0.000000

127.0.0.1 - - [2017-12-12 22:35:11] "GET /test/ HTTP/1.1" 200 126 0.000000

127.0.0.1 - - [2017-12-12 22:35

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值