Flask在数据返回时间歇性挂起

2024-03-28 16:06:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在CentOS 7.4中使用Python2.7.5中的Flask1.0.2。从route函数返回一个值时(例如,20%或30%的时间)有时会挂起。我已经通过在前面放置一个日志条目(即使调用挂起,该日志条目也会显示在日志中)验证了它一直到return语句。它发生在我的所有函数中,为了清晰起见,我将包含最简单的函数:

@my_app.route("/signingkey", methods=['GET'])
def signing_key():
    """
    signing_key:    Provides the client with the current signing key (the public portion of it) for the domain

    :return:        The contents of the public key
    """

    try:
        provision_app.logger.info("Providing signing key")
        return utility.get_signing_key(True), 200, CT_TP

    except Exception:
        return utility.get_exception_text(), 500, CT_TP

注:CT\u TP={'Content-Type':'text/plain'}

注:实用程序。获取\u签名\u密钥()将文本块作为str对象返回

我试过退回一个3.响应但这并没有改变症状。你知道吗

我正在apache2.4.6-80中通过WSGI运行Flask应用程序。我的WSGI文件如下所示:

import sys
sys.path.insert(0, '/opt/my_app/')
# noinspection PyPep8
from provision import my_app as application

我的Apache conf.d文件如下所示:

<VirtualHost *>
    WSGIDaemonProcess my_app user=my_app group=my_app threads=4 processes=8
    WSGIScriptAlias / /opt/my_app/myapp.wsgi

    <Directory /opt/my_app/>
        WSGIProcessGroup my_app
        WSGIApplicationGroup %{GLOBAL}
        Require all granted
    </Directory>
</VirtualHost>

服务器是一个VM(kvm),有4个vcpu和8GB的RAM。这个应用程序是服务器必须执行的唯一负载,很少有超过3%的CPU利用率(当应用程序投入生产时,这一点预计会更高,但在测试的这个阶段,服务器几乎没有压力)。你知道吗

我正在考虑重新启动服务器,但我真的很想知道烧瓶是怎么回事。你知道吗

任何帮助、想法或观察都将不胜感激。你知道吗


Tags: thekey函数服务器app应用程序returnmy