uwsgi:没有加载app.进入完全动态模式

Ros*_*one 13 flask uwsgi

在我的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
Run Code Online (Sandbox Code Playgroud)

我的app结构如下所示:

/adminserver
   app.py
   ...
Run Code Online (Sandbox Code Playgroud)

app.py有这些代码:

app = Flask(__name__)
...

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5003, debug=True)
Run Code Online (Sandbox Code Playgroud)

结果是,当我尝试卷曲我的服务器时,我收到此错误:

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 ***
Run Code Online (Sandbox Code Playgroud)

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

module,wsgi参数:string

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

可以从命令行使用-w设置此选项.

callable Argument:string默认值:application

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

Sea*_*ira 9

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

/some-dir
    module1.py
    module2.py
Run Code Online (Sandbox Code Playgroud)

如果在当前工作目录中启动python解释器,则/some-dir可以导入每个模块:

some-dir$ python
>>> import module1, module2
# Module1 and Module2 are now imported
Run Code Online (Sandbox Code Playgroud)

对于与您要导入的名称匹配的文件,Python搜索sys.path(以及其他一些内容,请参阅文档以import获取更多信息).uwsgi使用Python的导入过程来加载包含WSGI应用程序的模块.

可赎回

WSGI PEP(3333333)指定WSGI应用程序是一个可调用的,它接受两个参数并返回一个产生字节串的迭代:

# 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]
Run Code Online (Sandbox Code Playgroud)

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

wsgi_app = getattr(simple_wsgi, 'simple_app')
Run Code Online (Sandbox Code Playgroud)

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)
Run Code Online (Sandbox Code Playgroud)


Aus*_*ner 6

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

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