简体   繁体   English

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

[英]Can't run tornado app using gunicorn

I can't run tornado application using gunicorn. 我无法使用gunicorn运行龙卷风应用程序。 There is an error while startup app. 启动应用程序时出错。 I want to run it using gunicorn because I need some good features like: graceful-timeout, response-timeout and etc... 我想用gunicorn运行它,因为我需要一些很好的功能,如:graceful-timeout,response-timeout等...

tornado app: 龙卷风app:

$cat wsgi.py

source code: 源代码:

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

bash: 庆典:

$ gunicorn wsgi:app --bind 127.0.0.1:9080

traceback: 追溯:

[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

Any ideas? 有任何想法吗?

Update for Ben Darnell: Ben Darnell的更新

I tried this: 我试过这个:

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)

But result is the same: 但结果是一样的:

TypeError: 'WSGIAdapter' object is not iterable

works for me: 适合我:

gunicorn -k tornado wsgi:app

wsgi.py 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)
])

good luck! 祝好运!

To run in WSGI mode, return the WSGIAdapter; 要在WSGI模式下运行,请返回WSGIAdapter; do not use a WSGIContainer (WSGIContainer is for going the other direction, when you have a WSGI application to run on a tornado server). 不要使用WSGIContainer(当你有一个在龙卷风服务器上运行的WSGI应用程序时,WSGIContainer用于指向另一个方向)。 However, gunicorn has a native tornado mode so you will probably get better results in this mode than using WSGI. 但是,gunicorn具有原生龙卷风模式,因此您可能在此模式下获得比使用WSGI更好的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM