Rose Perrone
Rose Perrone

Reputation: 63556

uwsgi: no app loaded. going in full dynamic mode

In my uwsgi config, I have these options:

[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

My app structure looks like this:

/adminserver
   app.py
   ...

My app.py has these bits of code:

app = Flask(__name__)
...

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

The result is that when I try to curl my server, I get this error:

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 ***

What do the module and callable options do? The docs say:

module, wsgi Argument: string

Load a WSGI module as the application. The module (sans .py) must be importable, ie. be in PYTHONPATH.

This option may be set with -w from the command line.

callable Argument: string Default: application

Set default WSGI callable name.

Upvotes: 16

Views: 30896

Answers (3)

aircraft
aircraft

Reputation: 26896

First, check your configuration whether is correct.

my uwsgi.ini configuration:

[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

then use uwsgi --ini uwsgi.ini to run uwsgi.

if not work, you rm -rf the venv directory, and re-initial the venv, and re-try my step.

I re-initial the venv solved my issue, seems the problem is when I pip3 install some packages of requirements.txt, and upgrade the pip, then install uwsgi package. so, I delete the venv, and re-initial my virtual environment.

Upvotes: 0

Austin Wagner
Austin Wagner

Reputation: 1081

For anyone else having this problem, if you are sure your configuration is correct, you should check your uWSGI version.

Ubuntu 12.04 LTS provides 1.0.3. Removing that and using pip to install 2.0.4 resolved my issues.

Upvotes: 5

Sean Vieira
Sean Vieira

Reputation: 159955

Module

A module in Python maps to a file on disk - when you have a directory like this:

/some-dir
    module1.py
    module2.py

If you start up a python interpreter while the current working directory is /some-dir you will be able to import each of the modules:

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

Python searches sys.path (and a few other things, see the docs on import for more information) for a file that matches the name you are trying to import. uwsgi uses Python's import process under the covers to load the module that contains your WSGI application.

Callable

The WSGI PEPs (333 and 3333) specify that a WSGI application 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 needs to know the name of a symbol inside of your module that maps to the WSGI application callable, so it can pass in the environment and the start_response callable - essentially, it needs to be able to do the following:

wsgi_app = getattr(simple_wsgi, 'simple_app')

TL;PC (Too Long; Prefer Code)

A simple parallel of what uwsgi is doing:

# 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)

Upvotes: 11

Related Questions