0

I am trying to setup rethinkDB with tornado. This is my db setup -

db_connection = r.connect(RDB_HOST,RDB_PORT) #Connecting to RethinkDB server 
This is just for cross-checking database and table exists 
def dbSetup():
    print PROJECT_DB,db_connection
    try:
        r.db_create(PROJECT_DB).run(db_connection)
        print 'Database setup completed.'
    except RqlRuntimeError:
        try:
            r.db(PROJECT_DB).table_create(PROJECT_TABLE).run(connection)
            print 'Table creation completed'
        except:
            print 'Table already exists.Nothing to do'
        print 'App database already exists.Nothing to do'
    db_connection.close()

But the try block for db_create is throwing an AttributeError: 'Future' object has no attribute '_start'. I am unable to figure out what seems to be the problem here.

Ekwinder Saini
  • 270
  • 5
  • 18
  • I found this to be helpful : https://www.rethinkdb.com/docs/async-connections/#python-with-tornado-or-twisted – naoko Feb 01 '16 at 04:20

1 Answers1

0

rethinkdb has native async client for Tornado. The problem in your case is that connect returns only future that should be resolved (yield) - is asynchronous. And that object, Future, does not have anything like _start nor anything like rethink connection object. Example how to do it:

import rethinkdb as r
from tornado import ioloop, gen

r.set_loop_type("tornado")

@gen.coroutine
def dbSetup():
    db_connection = yield r.connect(RDB_HOST,RDB_PORT)
    yield r.db_create(PROJECT_DB).run(db_connection)
    print 'Database setup completed.'

tornado.ioloop.IOLoop.current().run_sync(dbSetup)

More information on https://rethinkdb.com/blog/async-drivers/

kwarunek
  • 12,141
  • 4
  • 43
  • 48