擅长:python、mysql、java
<p>您可以使用<code>grequests</code>。它允许其他greenlet在发出请求时运行。它与<code>requests</code>库兼容,并返回一个<code>requests.Response</code>对象。用法如下:</p>
<pre><code>import grequests
@app.route('/do', methods = ['POST'])
def do():
result = grequests.map([grequests.get('slow api')])
return result[0].content
</code></pre>
<p>编辑:我添加了一个测试,发现时间并没有随着grequests而增加,因为gunicorn的gevent工作程序在初始化时已经执行了猴子修补:<a href="https://github.com/benoitc/gunicorn/blob/master/gunicorn/workers/ggevent.py#L65" rel="nofollow">https://github.com/benoitc/gunicorn/blob/master/gunicorn/workers/ggevent.py#L65</a></p>