### Navigation
- [index](# "General Index")
- [modules](# "Python Module Index") |
- [next](# "Utilities") |
- [previous](# "tornado.platform.caresresolver — Asynchronous DNS Resolver using C-Ares") |
- [Tornado 4.4.dev1 documentation](#) »
- [Integration with other services](#) »
# `tornado.platform.twisted` — Bridges between Twisted and Tornado
Bridges between the Twisted reactor and Tornado IOLoop.
This module lets you run applications and libraries written forTwisted in a Tornado application. It can be used in two modes,depending on which library's underlying event loop you want to use.
This module has been tested with Twisted versions 11.0.0 and newer.
### Twisted on Tornado
*class *`tornado.platform.twisted.``TornadoReactor`(*io_loop=None*)[[source]](#)
Twisted reactor built on the Tornado IOLoop.
[`TornadoReactor`](# "tornado.platform.twisted.TornadoReactor") implements the Twisted reactor interface on top ofthe Tornado IOLoop. To use it, simply call [`install`](# "tornado.platform.twisted.install") at the beginningof the application:
~~~
import tornado.platform.twisted
tornado.platform.twisted.install()
from twisted.internet import reactor
~~~
When the app is ready to start, call `IOLoop.current().start()`instead of `reactor.run()`.
It is also possible to create a non-global reactor by calling`tornado.platform.twisted.TornadoReactor(io_loop)`. However, ifthe [`IOLoop`](# "tornado.ioloop.IOLoop") and reactor are to be short-lived (such as those used inunit tests), additional cleanup may be required. Specifically, it isrecommended to call:
~~~
reactor.fireSystemEvent('shutdown')
reactor.disconnectAll()
~~~
before closing the [`IOLoop`](# "tornado.ioloop.IOLoop").
Changed in version 4.1: The `io_loop` argument is deprecated.
`tornado.platform.twisted.``install`(*io_loop=None*)[[source]](#)
Install this package as the default Twisted reactor.
`install()` must be called very early in the startup process,before most other twisted-related imports. Conversely, because itinitializes the [`IOLoop`](# "tornado.ioloop.IOLoop"), it cannot be called before[`fork_processes`](# "tornado.process.fork_processes") or multi-process [`start`](# "tornado.tcpserver.TCPServer.start"). Theseconflicting requirements make it difficult to use [`TornadoReactor`](# "tornado.platform.twisted.TornadoReactor")in multi-process mode, and an external process manager such as`supervisord` is recommended instead.
Changed in version 4.1: The `io_loop` argument is deprecated.
### Tornado on Twisted
*class *`tornado.platform.twisted.``TwistedIOLoop`[[source]](#)
IOLoop implementation that runs on Twisted.
[`TwistedIOLoop`](# "tornado.platform.twisted.TwistedIOLoop") implements the Tornado IOLoop interface on top ofthe Twisted reactor. Recommended usage:
~~~
from tornado.platform.twisted import TwistedIOLoop
from twisted.internet import reactor
TwistedIOLoop().install()
# Set up your tornado application as usual using `IOLoop.instance`
reactor.run()
~~~
Uses the global Twisted reactor by default. To create multiple`TwistedIOLoops` in the same process, you must pass a unique reactorwhen constructing each one.
Not compatible with [`tornado.process.Subprocess.set_exit_callback`](# "tornado.process.Subprocess.set_exit_callback")because the `SIGCHLD` handlers used by Tornado and Twisted conflictwith each other.
### Twisted DNS resolver
*class *`tornado.platform.twisted.``TwistedResolver`[[source]](#)
Twisted-based asynchronous resolver.
This is a non-blocking and non-threaded resolver. It isrecommended only when threads cannot be used, since it haslimitations compared to the standard `getaddrinfo`-based[`Resolver`](# "tornado.netutil.Resolver") and[`ThreadedResolver`](# "tornado.netutil.ThreadedResolver"). Specifically, it returns atmost one result, and arguments other than `host` and `family`are ignored. It may fail to resolve when `family` is not`socket.AF_UNSPEC`.
Requires Twisted 12.1 or newer.
Changed in version 4.1: The `io_loop` argument is deprecated.
© Copyright 2009-2016, The Tornado Authors. Created using [Sphinx](http://sphinx-doc.org/) 1.3.5.
- User's guide
- Introduction
- Asynchronous and non-Blocking I/O
- Coroutines
- Queue example - a concurrent web spider
- Structure of a Tornado web application
- Templates and UI
- Authentication and security
- Running and deploying
- Web framework
- tornado.web — RequestHandler and Application classes
- tornado.template — Flexible output generation
- tornado.escape — Escaping and string manipulation
- tornado.locale — Internationalization support
- tornado.websocket — Bidirectional communication to the browser
- HTTP servers and clients
- tornado.httpserver — Non-blocking HTTP server
- tornado.httpclient — Asynchronous HTTP client
- tornado.httputil — Manipulate HTTP headers and URLs
- tornado.http1connection – HTTP/1.x client/server implementation
- Asynchronous networking
- tornado.ioloop — Main event loop
- tornado.iostream — Convenient wrappers for non-blocking sockets
- tornado.netutil — Miscellaneous network utilities
- tornado.tcpclient — IOStream connection factory
- tornado.tcpserver — Basic IOStream-based TCP server
- Coroutines and concurrency
- tornado.gen — Simplify asynchronous code
- tornado.concurrent — Work with threads and futures
- tornado.locks – Synchronization primitives
- tornado.queues – Queues for coroutines
- tornado.process — Utilities for multiple processes
- Integration with other services
- tornado.auth — Third-party login with OpenID and OAuth
- tornado.wsgi — Interoperability with other Python frameworks and servers
- tornado.platform.asyncio — Bridge between asyncio and Tornado
- tornado.platform.caresresolver — Asynchronous DNS Resolver using C-Ares
- tornado.platform.twisted — Bridges between Twisted and Tornado
- Utilities
- tornado.autoreload — Automatically detect code changes in development
- tornado.log — Logging support
- tornado.options — Command-line parsing
- tornado.stack_context — Exception handling across asynchronous callbacks
- tornado.testing — Unit testing support for asynchronous code
- tornado.util — General-purpose utilities
- Frequently Asked Questions
- Release notes
- What's new in Tornado 4.3
- What's new in Tornado 4.2.1
- What's new in Tornado 4.2
- What's new in Tornado 4.1
- What's new in Tornado 4.0.2
- What's new in Tornado 4.0.1
- What's new in Tornado 4.0
- What's new in Tornado 3.2.2
- What's new in Tornado 3.2.1
- What's new in Tornado 3.2
- What's new in Tornado 3.1.1
- What's new in Tornado 3.1
- What's new in Tornado 3.0.2
- What's new in Tornado 3.0.1
- What's new in Tornado 3.0
- What's new in Tornado 2.4.1
- What's new in Tornado 2.4
- What's new in Tornado 2.3
- What's new in Tornado 2.2.1
- What's new in Tornado 2.2
- What's new in Tornado 2.1.1
- What's new in Tornado 2.1
- What's new in Tornado 2.0
- What's new in Tornado 1.2.1
- What's new in Tornado 1.2
- What's new in Tornado 1.1.1
- What's new in Tornado 1.1
- What's new in Tornado 1.0.1
- What's new in Tornado 1.0