不能 运行 tornado 应用程序使用 gunicorn
Can't run tornado app using gunicorn
我不能 运行 tornado 应用程序使用 gunicorn。启动应用程序时出错。我想 运行 它使用 gunicorn 因为我需要一些好的功能,例如:优雅超时、响应超时等...
tornado 应用程序:
$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))
bash:
$ 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
到运行WSGI模式,returnWSGIAdapter;不要使用 WSGIContainer(WSGIContainer 用于另一个方向,当你有一个 WSGI 应用程序到龙卷风服务器上的 运行 时)。然而,gunicorn 有一个原生的龙卷风模式,所以你在这个模式下可能会比使用 WSGI 获得更好的结果。
适合我:
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)
])
祝你好运!
我不能 运行 tornado 应用程序使用 gunicorn。启动应用程序时出错。我想 运行 它使用 gunicorn 因为我需要一些好的功能,例如:优雅超时、响应超时等...
tornado 应用程序:
$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))
bash:
$ 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
到运行WSGI模式,returnWSGIAdapter;不要使用 WSGIContainer(WSGIContainer 用于另一个方向,当你有一个 WSGI 应用程序到龙卷风服务器上的 运行 时)。然而,gunicorn 有一个原生的龙卷风模式,所以你在这个模式下可能会比使用 WSGI 获得更好的结果。
适合我:
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)
])
祝你好运!