Python 在flask中使用Gevent:API不是异步的

Python 在flask中使用Gevent:API不是异步的,python,multithreading,asynchronous,flask,waitress,Python,Multithreading,Asynchronous,Flask,Waitress,早些时候我用的是女服务员。现在我正在运行我的Flask应用程序,它只有一个API from flask import Flask, request, jsonify import documentUtil from gevent.pywsgi import WSGIServer app = Flask(__name__) @app.route('/post-document-string', methods=['POST']) def parse_data(): req_data

早些时候我用的是女服务员。现在我正在运行我的Flask应用程序,它只有一个API

from flask import Flask, request, jsonify
import documentUtil
from gevent.pywsgi import WSGIServer

app = Flask(__name__)

@app.route('/post-document-string', methods=['POST']) 
def parse_data():
    req_data = request.get_json(force=True)
    text = req_data['text']
    result = documentUtil.parse(text)
    return jsonify(keywords = result)

if __name__=='__main__':
    http_server = WSGIServer(('127.0.0.1', 8000), app)
    http_server.serve_forever()
这个很好用。但是API不是异步的。如果从前端同时触发两次相同的API,则第二个调用将等待第一个调用首先给出响应


这里怎么了?如何使其异步?

我们使用Gunicorn在多个进程中运行Flask。通过这种方式,你可以从python中获得更多的能量+自动重启等等。示例配置文件:

import multiprocessing

bind = "0.0.0.0:80"
workers = (multiprocessing.cpu_count() * 2) + 1
# ... additional config
然后带着类似的东西跑

gunicorn --config /path/to/file application.app

我们使用Gunicorn在多个进程中运行Flask。通过这种方式,你可以从python中获得更多的能量+自动重启等等。示例配置文件:

import multiprocessing

bind = "0.0.0.0:80"
workers = (multiprocessing.cpu_count() * 2) + 1
# ... additional config
然后带着类似的东西跑

gunicorn --config /path/to/file application.app

不确定,但是我认为在服务器对象中添加线程参数可以解决这个问题

http_server=WSGIServer(('127.0.0.1',8000),app,numthreads=50)


来源:

不确定,但是我认为在服务器对象中添加线程参数可以解决这个问题

http_server=WSGIServer(('127.0.0.1',8000),app,numthreads=50)


来源:

显然,这是女服务员经常遇到的问题。可能会更改代码以使用uWSGI。配置非常简单。(我没有投反对票)显然,这是一个反复出现在女服务员身上的问题。可能会更改代码以使用uWSGI。配置非常简单。(我没有否决)
得到一个意外的关键字参数'numthreads'
得到一个意外的关键字参数'numthreads'