tornado.platform.asyncio — Bridge between asyncio and Tornado¶
Bridges between the asyncio module and Tornado IOLoop.
3.2 新版功能.
This module integrates Tornado with the asyncio module introduced
in Python 3.4. This makes it possible to combine the two libraries on
the same event loop.
5.0 版后已移除: While the code in this module is still used, it is now enabled
automatically when asyncio is available, so applications should
no longer need to refer to this module directly.
注解
Tornado requires the add_reader family of
methods, so it is not compatible with the ProactorEventLoop on
Windows. Use the SelectorEventLoop instead.
-
class
tornado.platform.asyncio.AsyncIOMainLoop[源代码]¶ AsyncIOMainLoopcreates anIOLoopthat corresponds to the currentasyncioevent loop (i.e. the one returned byasyncio.get_event_loop()).5.0 版后已移除: Now used automatically when appropriate; it is no longer necessary to refer to this class directly.
在 5.0 版更改: Closing an
AsyncIOMainLoopnow closes the underlying asyncio loop.
-
class
tornado.platform.asyncio.AsyncIOLoop[源代码]¶ AsyncIOLoopis anIOLoopthat runs on anasyncioevent loop. This class follows the usual Tornado semantics for creating newIOLoops; these loops are not necessarily related to theasynciodefault event loop.Each
AsyncIOLoopcreates a newasyncio.EventLoop; this object can be accessed with theasyncio_loopattribute.在 5.0 版更改: When an
AsyncIOLoopbecomes the currentIOLoop, it also sets the currentasyncioevent loop.5.0 版后已移除: Now used automatically when appropriate; it is no longer necessary to refer to this class directly.
-
tornado.platform.asyncio.to_tornado_future(asyncio_future)[源代码]¶ Convert an
asyncio.Futureto atornado.concurrent.Future.4.1 新版功能.
5.0 版后已移除: Tornado
Futureshave been merged withasyncio.Future, so this method is now a no-op.
-
tornado.platform.asyncio.to_asyncio_future(tornado_future)[源代码]¶ Convert a Tornado yieldable object to an
asyncio.Future.4.1 新版功能.
在 4.3 版更改: Now accepts any yieldable object, not just
tornado.concurrent.Future.5.0 版后已移除: Tornado
Futureshave been merged withasyncio.Future, so this method is now equivalent totornado.gen.convert_yielded.
-
class
tornado.platform.asyncio.AnyThreadEventLoopPolicy[源代码]¶ Event loop policy that allows loop creation on any thread.
The default
asyncioevent loop policy only automatically creates event loops in the main threads. Other threads must create event loops explicitly orasyncio.get_event_loop(and thereforeIOLoop.current) will fail. Installing this policy allows event loops to be created automatically on any thread, matching the behavior of Tornado versions prior to 5.0 (or 5.0 on Python 2).Usage:
asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy())
5.0 新版功能.