Skip to content

Instantly share code, notes, and snippets.

@yanmhlv
Last active December 30, 2015 11:19
Show Gist options
  • Save yanmhlv/7821554 to your computer and use it in GitHub Desktop.
Save yanmhlv/7821554 to your computer and use it in GitHub Desktop.
example for motor and tornado
import motor
import tornado.gen as gen
@gen.coroutine
def foo1():
conn = motor.MotorClient().open_sync()
db = conn['test']
result = yield gen.Task(db.accounts.find().limit(10).to_list)
return result
@coroutine
def foo2():
conn = motor.MongoClient().open_sync()
db = conn['test']
result = yield motor.Op(db.users.find().sort([('_id', -1)]).limit(20).to_list)
return result
import tornado.ioloop
print foo1()
print foo2()
tornado.ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment