由于 {built-in method poll},Flask 应用最多需要 4 秒才能加载

Flask app takes up to 4 seconds to load because of {built-in method poll}

我不确定为什么会这样,但我的 Flask 应用程序加载初始请求需要将近 4 秒的时间。我已将它连接到一个分析器,它显示了这一点:

PATH: '/'
         37033 function calls (34635 primitive calls) in 4.029 seconds

   Ordered by: internal time, call count
   List reduced from 1405 to 30 due to restriction <30>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        8    3.888    0.486    3.888    0.486 {built-in method poll}

这只会发生在初始请求上,任何后续请求几乎都会立即得到解决。

我目前 运行从 manage.py 使用:

@manager.command
def profile():
    app.config['PROFILE'] = True
    app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30])
    app.run()

但是无论我 运行 在本地使用 gunicorn,还是在生产环境中使用 nginx 反向代理到 gunicorn,都会有延迟。

我这辈子都搞不懂 {built-in method poll} 是什么,为什么加载我的应用程序需要 4 秒。

这是烧瓶资产配置不当的结果。不要这样做:

     'public/css/vendor/font-awesome.min.css',
     Bundle('public/css/app.styl',
-           depends='/**/*.styl',
            filters='stylus',
            output='public/css/app.css'),
     filters='cssmin',

- 表明不要做愚蠢的事情。