停靠的Python应用程序在EC2上占用100%的CPU

停靠的Python应用程序在EC2上占用100%的CPU,python,amazon-ec2,Python,Amazon Ec2,我已经在EC2上部署了python应用程序,但python占用了100%的CPU使用率。 下面是我认为问题所在的代码片段 @app.route("/refresh", methods=["POST"]) def preprocess(): start_time = time.time() if flask.request.content_type == "application/json": input_data = flask.request.data.dec

我已经在EC2上部署了python应用程序,但python占用了100%的CPU使用率。 下面是我认为问题所在的代码片段

@app.route("/refresh", methods=["POST"])
def preprocess():
    start_time = time.time()

    if flask.request.content_type == "application/json":
        input_data = flask.request.data.decode("utf-8")
    else:
        return flask.Response(
        response='{"Error: Request content type error, REQUIRED: application/json "}',
        status=415,
        mimetype="application/json")

    input_dictionary = ast.literal_eval(input_data)

    prepare_obj = Prepare()
    prepare_output = prepare_obj.preparation()

    end_time = time.time()
    return flask.Response(response=resp, status=200, mimetype="application/json")

“时间”模块是否导致问题?我们有两个EC2实例。在一个EC2中,我没有得到这个问题。但在我面临的另一个EC2实例中。

不太可能,输入数据真正有什么?输入数据包含json,这是一个API请求。您是否有可能使用
app.run(debug=True)
?app.run(主机=0.0.0,端口=端口号)。我正在使用它。请尝试在
end\u time=time.time()之后添加
time.sleep(0.5)