【问题标题】:uwsgi: no app loaded. going in full dynamic modeuwsgi:没有加载应用程序。进入全动态模式
【发布时间】:2013-09-11 23:40:51
【问题描述】:

在我的 uwsgi 配置中,我有以下选项:

[uwsgi]
chmod-socket = 777
socket = 127.0.0.1:9031
plugins = python
pythonpath = /adminserver/
callable = app
master = True
processes = 4
reload-mercy = 8
cpu-affinity = 1
max-requests = 2000
limit-as = 512
reload-on-as = 256
reload-on-rss = 192
no-orphans
vacuum

我的应用结构如下所示:

/adminserver
   app.py
   ...

我的app.py 有这些代码:

app = Flask(__name__)
...

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5003, debug=True)

结果是当我尝试 curl 我的服务器时,我得到了这个错误:

Wed Sep 11 23:28:56 2013 - added /adminserver/ to pythonpath.
Wed Sep 11 23:28:56 2013 - *** no app loaded. going in full dynamic mode ***
Wed Sep 11 23:28:56 2013 - *** uWSGI is running in multiple interpreter mode ***

modulecallable 选项有什么作用?文档说:

模块,wsgi 参数:字符串

加载一个 WSGI 模块作为应用程序。模块(sans .py)必须是 可导入的,即在 PYTHONPATH 中。

此选项可以在命令行中使用 -w 设置。

可调用参数:字符串默认值:应用程序

设置默认的 WSGI 可调用名称。

【问题讨论】:

  • 您当前的配置似乎没有modulewsgi 键...

标签: flask uwsgi


【解决方案1】:

模块

Python 中的模块映射到磁盘上的文件 - 当您有这样的目录时:

/some-dir
    module1.py
    module2.py

如果您在当前工作目录为/some-dir 时启动python 解释器,您将能够导入每个模块:

some-dir$ python
>>> import module1, module2
# Module1 and Module2 are now imported

Python 在sys.path(以及其他一些东西,see the docs on import for more information)中搜索与您尝试导入的名称匹配的文件。 uwsgi 在后台使用 Python 的导入过程来加载包含您的 WSGI 应用程序的模块。

可调用

WSGI PEP(3333333)指定 WSGI 应用程序 is a callable that takes two arguments and returns an iterable that yields bytestrings

# simple_wsgi.py
# The simplest WSGI application
HELLO_WORLD = b"Hello world!\n"

def simple_app(environ, start_response):
    """Simplest possible application object"""
    status = '200 OK'
    response_headers = [('Content-type', 'text/plain')]
    start_response(status, response_headers)
    return [HELLO_WORLD]

uwsgi 需要知道模块内部映射到 WSGI 应用程序可调用的符号的名称,因此它可以传入环境和 start_response 可调用 - 本质上,它需要能够执行以下操作:

wsgi_app = getattr(simple_wsgi, 'simple_app')

TL;PC(太长;首选代码)

uwsgi 正在做的一个简单的平行:

# Use `module` to know *what* to import
import simple_wsgi

# construct request environment from user input
# create a callable to pass for start_response
# and then ...

# use `callable` to know what to call
wsgi_app = getattr(simple_wsgi, 'simple_app')

# and then call it to respond to the user
response = wsgi_app(environ, start_response)

【讨论】:

  • 我的uwsgi 配置文件中定义的module 应该是包含simple_app wgsi 应用程序的python 文件吗?它不起作用,但我不确定uwsgi 如何找到它在错误no app loaded 中引用的应用程序。
  • @RosePerrone - 据我了解,是的 module 应该与您要导入的磁盘上的文件名匹配。错误消息不是指一个应用程序,它是指一个应用程序的缺少,它只是使用通用名称。
【解决方案2】:

对于遇到此问题的其他人,如果您确定您的配置正确,则应检查您的 uWSGI 版本。

Ubuntu 12.04 LTS 提供 1.0.3。删除它并使用 pip 安装 2.0.4 解决了我的问题。

【讨论】:

    【解决方案3】:

    首先,检查你的配置是否正确。

    我的uwsgi.ini 配置:

    [uwsgi]
    chdir=/home/air/repo/Qiy
    uid=nobody
    gid=nobody
    module=Qiy.wsgi:application
    socket=/home/air/repo/Qiy/uwsgi.sock
    master=true
    workers=5
    pidfile=/home/air/repo/Qiy/uwsgi.pid
    vacuum=true
    thunder-lock=true
    enable-threads=true
    harakiri=30
    post-buffering=4096
    daemonize=/home/air/repo/Qiy/uwsgi.log
    

    然后使用uwsgi --ini uwsgi.ini 运行uwsgi。

    如果不行,你rm -rfvenv目录,重新初始化venv,重试我的步骤。

    我重新初始化venv解决了我的问题,似乎问题是当我pip3 installrequirements.txt的一些包,升级pip,然后安装uwsgi包。所以,我删除了venv,并重新初始化了我的虚拟环境。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-12
      • 1970-01-01
      • 1970-01-01
      • 2019-11-19
      • 1970-01-01
      • 2017-04-26
      • 2023-03-27
      • 1970-01-01
      相关资源
      最近更新 更多