This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Tornado nested callback example

By: a guest on Jun 21st, 2012  |  syntax: Python  |  size: 0.48 KB  |  views: 46  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. from tornado import gen
  2. import tornado.web
  3.  
  4. class MainHandler(tornado.web.RequestHandler):
  5.     @tornado.web.asynchronous
  6.     @gen.engine
  7.     def get(self):
  8.         cool_result = yield gen.Task(self.nested, 2)
  9.         self.write(cool_result)
  10.  
  11.     @gen.engine
  12.     def nested(self, result_outer, callback = {}):
  13.         result = yield gen.Task(self.asum, [1,result_outer])
  14.         callback(result)
  15.  
  16.     def asum(self, l, callback={}):
  17.         r = sum(l)
  18.         return callback(r)
clone this paste RAW Paste Data