Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 70 lines (49 sloc) 2.403 kb
3654790 @bdarnell Implement TwistedIOLoop, to bridge the gap with Twisted in the other dir...
bdarnell authored
1 ``tornado.platform.twisted`` --- Bridges between Twisted and Tornado
f28674d @bdarnell Document tornado.platform.twisted, and rename ioloop parameter to io_loo...
bdarnell authored
2 ========================================================================
3
4 .. module:: tornado.platform.twisted
5
3654790 @bdarnell Implement TwistedIOLoop, to bridge the gap with Twisted in the other dir...
bdarnell authored
6 This module lets you run applications and libraries written for
7 Twisted in a Tornado application. It can be used in two modes,
8 depending on which library's underlying event loop you want to use.
9
6bf30d0 @bdarnell Add/update docs for twisted, caresresolver, and util modules
bdarnell authored
10 This module has been tested with Twisted versions 11.0.0 and newer.
11
3654790 @bdarnell Implement TwistedIOLoop, to bridge the gap with Twisted in the other dir...
bdarnell authored
12 Twisted on Tornado
13 ------------------
14
6bf30d0 @bdarnell Add/update docs for twisted, caresresolver, and util modules
bdarnell authored
15 .. py:class:: TornadoReactor
f28674d @bdarnell Document tornado.platform.twisted, and rename ioloop parameter to io_loo...
bdarnell authored
16
6bf30d0 @bdarnell Add/update docs for twisted, caresresolver, and util modules
bdarnell authored
17 ``TornadoReactor`` implements the Twisted reactor interface on top of
18 the Tornado IOLoop. To use it, simply call ``install`` at the beginning
19 of the application::
af940f4 @bdarnell Major update to tornado.platform.twisted.
bdarnell authored
20
6bf30d0 @bdarnell Add/update docs for twisted, caresresolver, and util modules
bdarnell authored
21 import tornado.platform.twisted
22 tornado.platform.twisted.install()
23 from twisted.internet import reactor
af940f4 @bdarnell Major update to tornado.platform.twisted.
bdarnell authored
24
6bf30d0 @bdarnell Add/update docs for twisted, caresresolver, and util modules
bdarnell authored
25 When the app is ready to start, call ``IOLoop.instance().start()``
26 instead of ``reactor.run()``.
af940f4 @bdarnell Major update to tornado.platform.twisted.
bdarnell authored
27
6bf30d0 @bdarnell Add/update docs for twisted, caresresolver, and util modules
bdarnell authored
28 It is also possible to create a non-global reactor by calling
29 ``tornado.platform.twisted.TornadoReactor(io_loop)``. However, if
30 the `.IOLoop` and reactor are to be short-lived (such as those used in
31 unit tests), additional cleanup may be required. Specifically, it is
32 recommended to call::
af940f4 @bdarnell Major update to tornado.platform.twisted.
bdarnell authored
33
6bf30d0 @bdarnell Add/update docs for twisted, caresresolver, and util modules
bdarnell authored
34 reactor.fireSystemEvent('shutdown')
35 reactor.disconnectAll()
36
37 before closing the `.IOLoop`.
af940f4 @bdarnell Major update to tornado.platform.twisted.
bdarnell authored
38
3654790 @bdarnell Implement TwistedIOLoop, to bridge the gap with Twisted in the other dir...
bdarnell authored
39 Tornado on Twisted
40 ------------------
f28674d @bdarnell Document tornado.platform.twisted, and rename ioloop parameter to io_loo...
bdarnell authored
41
6bf30d0 @bdarnell Add/update docs for twisted, caresresolver, and util modules
bdarnell authored
42 .. py:class:: TwistedIOLoop
f28674d @bdarnell Document tornado.platform.twisted, and rename ioloop parameter to io_loo...
bdarnell authored
43
6bf30d0 @bdarnell Add/update docs for twisted, caresresolver, and util modules
bdarnell authored
44 ``TwistedIOLoop`` implements the Tornado IOLoop interface on top
45 of the Twisted reactor. Recommended usage::
af940f4 @bdarnell Major update to tornado.platform.twisted.
bdarnell authored
46
6bf30d0 @bdarnell Add/update docs for twisted, caresresolver, and util modules
bdarnell authored
47 from tornado.platform.twisted import TwistedIOLoop
48 from twisted.internet import reactor
49 TwistedIOLoop().install()
50 # Set up your tornado application as usual using `IOLoop.instance`
51 reactor.run()
af940f4 @bdarnell Major update to tornado.platform.twisted.
bdarnell authored
52
6bf30d0 @bdarnell Add/update docs for twisted, caresresolver, and util modules
bdarnell authored
53 ``TwistedIOLoop`` always uses the global Twisted reactor.
54
55 Twisted DNS resolver
56 --------------------
57
58 .. py:class:: TwistedResolver
59
60 This is a non-blocking and non-threaded resolver. It is
61 recommended only when threads cannot be used, since it has
62 limitations compared to the standard ``getaddrinfo``-based
63 `~tornado.netutil.Resolver` and
64 `~tornado.netutil.ThreadedResolver`. Specifically, it returns at
65 most one result, and arguments other than ``host`` and ``family``
66 are ignored. It may fail to resolve when ``family`` is not
67 ``socket.AF_UNSPEC``.
68
69 Requires Twisted 12.1 or newer.
Something went wrong with that request. Please try again.