无法使用gunicorn运行龙卷风应用程序

时间:2015-07-06 11:57:57

标签: python python-2.7 tornado wsgi gunicorn

我无法使用gunicorn运行龙卷风应用程序。启动应用程序时出错。我想用gunicorn运行它,因为我需要一些很好的功能,如:graceful-timeout,response-timeout等等......

龙卷风app:

$cat wsgi.py

源代码:

import tornado.web
import tornado.wsgi
from api.handler import MainHandler, ApiV2Handler, InvalidRequestHandler


def app(*args):
    app = tornado.web.Application([
        (r"/", MainHandler),
        (r"(/v3/(\w+)/(\w+)/)", ApiV2Handler),
        (r"(/v3/(\w+)/(\w+))", InvalidRequestHandler)
    ])
    return tornado.wsgi.WSGIContainer(tornado.wsgi.WSGIAdapter(app))

击:

$ gunicorn wsgi:app --bind 127.0.0.1:9080

回溯:

[2015-07-06 14:41:16 +0000] [21806] [INFO] Starting gunicorn 19.3.0
[2015-07-06 14:41:16 +0000] [21806] [INFO] Listening at: http://127.0.0.1:9080 (21806)
[2015-07-06 14:41:16 +0000] [21806] [INFO] Using worker: sync
[2015-07-06 14:41:16 +0000] [21811] [INFO] Booting worker with pid: 21811
[2015-07-06 14:41:21 +0000] [21811] [ERROR] Error handling request
Traceback (most recent call last):
  File "venv/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 130, in handle
    self.handle_request(listener, req, client, addr)
  File "venv/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
    for item in respiter:
TypeError: 'WSGIContainer' object is not iterable
^C[2015-07-06 14:41:23 +0000] [21806] [INFO] Handling signal: int
[2015-07-06 14:41:23 +0000] [21811] [INFO] Worker exiting (pid: 21811)
[2015-07-06 14:41:23 +0000] [21806] [INFO] Shutting down: Master

有什么想法吗?

Ben Darnell的

更新

我试过了:

import tornado.web
import tornado.wsgi
from api.handler import MainHandler, ApiV2Handler, InvalidRequestHandler


def app(*args):
    app = tornado.web.Application([
        (r"/", MainHandler),
        (r"(/v3/(\w+)/(\w+)/)", ApiV2Handler),
        (r"(/v3/(\w+)/(\w+))", InvalidRequestHandler)
    ])
    return tornado.wsgi.WSGIAdapter(app)

但结果是一样的:

TypeError: 'WSGIAdapter' object is not iterable

2 个答案:

答案 0 :(得分:1)

适合我:

gunicorn -k tornado wsgi:app

wsgi.py

import tornado.web
import tornado.wsgi
from api.handler import MainHandler, ApiV2Handler, InvalidRequestHandler

app = tornado.web.Application([
    (r"/", MainHandler),
    (r"(/v3/(\w+)/(\w+)/)", ApiV2Handler),
    (r"(/v3/(\w+)/(\w+))", InvalidRequestHandler)
])
祝你好运!

答案 1 :(得分:0)

要在WSGI模式下运行,请返回WSGIAdapter;不要使用WSGIContainer(当你在龙卷风服务器上运行WSGI应用程序时,WSGIContainer用于指向另一个方向)。但是,gunicorn具有原生龙卷风模式,因此您可能会在此模式下获得比使用WSGI更好的结果。