tornado.wsgi
——与其他python框架和服务器的互操作性¶
支持Tornado Web框架的wsgi。
wsgi是Web服务器的python标准,允许Tornado与其他python Web框架和服务器之间的互操作性。
此模块通过 WSGIContainer
类,这样就可以在Tornado HTTP服务器上使用其他wsgi框架运行应用程序。不支持反转; Tornado Application
和 RequestHandler
类设计用于 Tornado HTTPServer
并且不能在通用的wsgi容器中使用。
- class tornado.wsgi.WSGIContainer(wsgi_application: WSGIAppType)[源代码]¶
使wsgi兼容函数在Tornado的HTTP服务器上运行。
警告
WSGI是 同步的 接口,而Tornado的并发模型是基于单线程异步执行的。这意味着使用Tornado的
WSGIContainer
是 不可扩展 比在多线程的wsgi服务器上运行相同的应用程序gunicorn
或uwsgi
. 使用WSGIContainer
只有当Tornado和WSGi在同一个过程中结合起来的好处大于减少的可伸缩性时。将wsgi函数包装在
WSGIContainer
并把它传递给HTTPServer
运行它。例如::def simple_app(environ, start_response): status = "200 OK" response_headers = [("Content-type", "text/plain")] start_response(status, response_headers) return [b"Hello world!\n"] container = tornado.wsgi.WSGIContainer(simple_app) http_server = tornado.httpserver.HTTPServer(container) http_server.listen(8888) tornado.ioloop.IOLoop.current().start()
此类旨在让其他框架(django、web.py等)在Tornado HTTP服务器和I/O循环上运行。
这个
tornado.web.FallbackHandler
类通常用于在同一服务器中混合Tornado和WSGi应用程序。完整示例请参见https://github.com/bdarnell/django-tornado-demo。- static environ(request: tornado.httputil.HTTPServerRequest) Dict[str, Any] [源代码]¶
转换A
tornado.httputil.HTTPServerRequest
到WSGi环境。