我制作了用于制作聊天机器人服务器的微型服务器。 我使用了 HTML/CSS 和 Flask。 我想制作一个可以同时让 10 个客户端使用的服务器。 所以我在 Flask 中使用了多处理的方法。 但我不确定如何检查它能否同时负担 10 人。
from flask import Flask, render_template, request
import threading
import openai
app = Flask(__name__)
lock = threading.Lock()
# Set up OpenAI API credentials
openai.api_key = 'API_KEY'
# Define the default route to return the index.html file
@app.route("/")
def index():
return render_template("index.html")
# Define the /api route to handle POST requests
@app.route("/api", methods=["POST"])
def api():
lock.acquire()
# Get the message from the POST request
message = request.json.get("message")
#PROCESS
lock.release()
if __name__=='__main__':
app.run(host='0.0.0.0', port=8080, threaded=False, processes=10)
所以对于多用户,我使用线程来阻止死锁我使用锁定和释放,在 app.run 我添加了 processes = 10 以仅获得 10 个用户。
有没有办法检查这个服务器是否同时为 10 个用户工作?