r.set_loop_type(string)
Set an asynchronous event loop model. There are two supported models:
"tornado"
: use the Tornado web framework. Under this model, the connect and run commands will return Tornado Future
objects."twisted"
: use the Twisted networking engine. Under this model, the connect and run commands will return Twisted Deferred
objects."gevent"
: use the gevent networking library. (Unlike the other asynchronous models, this does not change connect and run handling; inside the event loop, this is indistinguishable from the default Python driver.)"asyncio"
: use Python 3’s asyncio package. Under this model, the connect and run commands will return asyncio Future
objects.Example: Read a table’s data using Tornado.
r.set_loop_type("tornado")
conn = r.connect(host='localhost', port=28015)
@gen.coroutine
def use_cursor(conn):
# Print every row in the table.
cursor = yield r.table('test').order_by(index="id").run(yield conn)
while (yield cursor.fetch_next()):
item = yield cursor.next()
print(item)
For a longer discussion with both Tornado and Twisted examples, see the documentation article on Asynchronous connections.
Couldn't find what you were looking for?
Contribute: edit this page or open an issue