tornado.wsgi — Interoperability with other Python frameworks and servers¶
- WSGIAdapter converts a to the WSGI applicationinterface. This is useful for running a Tornado app on anotherHTTP server, such as Google App Engine. See the WSGIAdapter classdocumentation for limitations that apply.
- class
WSGIAdapter
(application)¶
Converts a instance into a WSGI application.
Example usage:
See the appengine demofor an example of using this module to run a Tornado app on GoogleApp Engine.
In WSGI mode asynchronous methods are not supported. This meansthat it is not possible to use , or thetornado.auth
or modules.
4.0 新版功能.
- _class
tornado.wsgi.
(handlers=None, default_host='', transforms=None, **settings)[源代码]
A WSGI equivalent oftornado.web.Application
.
4.0 版后已移除: Use a regular and wrap it inWSGIAdapter
instead.
Running WSGI apps on Tornado servers¶
- class
tornado.wsgi.
WSGIContainer
(wsgi_application)[源代码]
Makes a WSGI-compatible function runnable on Tornado’s HTTP server.
警告
WSGI is a synchronous interface, while Tornado’s concurrency modelis based on single-threaded asynchronous execution. This means thatrunning a WSGI app with Tornado’sWSGIContainer
is less scalable_than running the same app in a multi-threaded WSGI server like oruwsgi
. Use only when there arebenefits to combining Tornado and WSGI in the same process thatoutweigh the reduced scalability.
Wrap a WSGI function in aWSGIContainer
and pass it to torun it. For example:- def simple_app(environ, start_response):
status = "200 OK"
response_headers = [("Content-type", "text/plain")]
start_response(status, response_headers)
return ["Hello world!\n"]
container = tornado.wsgi.WSGIContainer(simple_app)
http_server = tornado.httpserver.HTTPServer(container)
http_server.listen(8888)
tornado.ioloop.IOLoop.current().start()
This class is intended to let other frameworks (Django, web.py, etc)run on the Tornado HTTP server and I/O loop.
Thetornado.web.FallbackHandler
class is often useful for mixingTornado and WSGI apps in the same server. See for a complete example.- _static
environ
(request)[源代码]
Converts a to a WSGI environment.
- def simple_app(environ, start_response):