2015-07-06 68 views
4

我不能運行使用gunicorn的龍捲風應用程序。啓動應用程序時出現錯誤。我想運行它使用gunicorn因爲我需要一些很好的功能,如:優雅超時,響應超時等..不能運行使用gunicorn的龍捲風應用程序

龍捲風應用:

$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 

任何想法?

更新本·達內爾:

我嘗試這樣做:

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 
+1

看起來像gunicorn期待'app'成爲'WSGIAdapter'對象,而不是返回WSGI應用程序的函數。 –

回答

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

好運!

+0

這是否允許websockets? –

0

要WSGI模式下運行,返回WSGIAdapter;不要使用WSGIContainer(當你有一個WSGI應用程序在龍捲風服務器上運行時,WSGIContainer用於其他方向)。然而,gunicorn有一個原生的龍捲風模式,所以你可能在這個模式下比使用WSGI獲得更好的結果。