Skip to content

Instantly share code, notes, and snippets.

@puentesarrin
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save puentesarrin/0d76abb80faae3e0b743 to your computer and use it in GitHub Desktop.
Save puentesarrin/0d76abb80faae3e0b743 to your computer and use it in GitHub Desktop.
import motor
from functools import partial
from tornado import gen, ioloop, web
class MyHandler(web.RequestHandler):
@gen.coroutine
def get(self):
count = yield self.settings['db'].collection.count()
self.finish(str(count))
@gen.coroutine
def validate_data(db):
yield db.collection.insert({'foo': 'bar'})
count = yield db.collection.count()
print(count)
def main():
db = motor.MotorClient().test
app = web.Application([(r'/', MyHandler)], db=db)
app.listen(8082)
validate_partial = partial(validate_data, db)
periodic_callback = ioloop.PeriodicCallback(validate_partial, 1000)
periodic_callback.start()
loop = ioloop.IOLoop.current()
loop.start()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment