Wes Mason
result = yield motor.Op(db.messages.insert, {'msg': msg}) # vs. db.messages.insert( {'msg': msg}, callback=self._on_response)
import tornado.web from sys import exit from .handlers import ResourceHandler def main(): application = tornado.web.Application(( (r"/resources/", ResourceHandler, "resources-root") ),) application.listen(port=8888, address='0.0.0.0') return tornado.ioloop.IOLoop.instance().start() if __name__ == "__main__": exit(main())
import time from tornado.web import asynchronous, RequestHandler class ResourceHandler(RequestHandler): def prepare(self): self.user_id = self.get_argument('user') @asynchronous def get(self): tornado.ioloop.IOLoop.instance().add_timeout( time.time()+60, self._end) def _end(self): self.finish('hello world!')
"""bobs_big_data.py""" import requests class BigData(object): ... def post(self): r = requests.post(self.url, data=self.data) return r.json()
import bobs_big_data from tornado.web import RequestHandler from trequests import setup_session from tornalet import tornalet setup_session() class WebHandler(RequestHandler): @tornalet def get(self): data = {'foo': 'bar'} response = bobs_big_data.BigData(data).post() return self.write(response)