tornado.platform.asyncio — Bridge between asyncio and Tornado¶
New in version 3.2.
This module integrates Tornado with the asyncio module introduced
in Python 3.4 (and available as a separate download for Python 3.3). This makes
it possible to combine the two libraries on the same event loop.
Most applications should use AsyncIOMainLoop to run Tornado on the
default asyncio event loop. Applications that need to run event
loops on multiple threads may use AsyncIOLoop to create multiple
loops.
Note
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()). Recommended usage:from tornado.platform.asyncio import AsyncIOMainLoop import asyncio AsyncIOMainLoop().install() asyncio.get_event_loop().run_forever()
-
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. Recommended usage:from tornado.ioloop import IOLoop IOLoop.configure('tornado.platform.asyncio.AsyncIOLoop') IOLoop.instance().start()
Each
AsyncIOLoopcreates a newasyncio.EventLoop; this object can be accessed with theasyncio_loopattribute.
-
tornado.platform.asyncio.to_tornado_future()¶ Convert an
asyncio.Futureto atornado.concurrent.Future.New in version 4.1.
-
tornado.platform.asyncio.to_asyncio_future()¶ Convert a
tornado.concurrent.Futureto anasyncio.Future.New in version 4.1.