5

The question can be devided on two separate parts.

  1. I have the following project stucture

    |- project | |-- app/ - directory with actual project code | |-- app.py - imports something from app/ and call create_app 

    When I run gunicorn I should point him to app object which is actually created in app.py. So I get an error because gunicorn treats app:app as a package. The only way is to rename something?

  2. I use factory method to create app. So I import create_app fuction in app.py and pass it to Manager from flask.ext.script. I pass manager object to gunicorn. In this case gunicorn runs correctly but once the first request comes I get the following error:

    [2015-03-25 15:38:11 +0000] [14395] [ERROR] Error handling request Traceback (most recent call last): File "/opt/env/local/lib/python2.7/site-packages/gunicorn/workers/async.py", line 52, in handle self.handle_request(listener_name, req, client, addr) File "/opt/env/local/lib/python2.7/site-packages/gunicorn/workers/ggevent.py", line 159, in handle_request super(GeventWorker, self).handle_request(*args) File "/opt/env/local/lib/python2.7/site-packages/gunicorn/workers/async.py", line 105, in handle_request respiter = self.wsgi(environ, resp.start_response) TypeError: __call__() takes at most 2 arguments (3 given) 

    Perhaps I could create some file wsgi.py and provide current app for gunicorn ?

1 Answer 1

4

You will have issues if two things named "app" are in the same directory in Python's path.

You need to pass a Flask app instance directly to gunicorn. The command line manager is not a WSGI app, which is why you get that error.

You can simply point gunicorn directly at a call to your app factory, there is no need for any intermediate code.

gunicorn app:create_app() 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.