Created
August 13, 2013 14:34
-
-
Save mayflaver/6221699 to your computer and use it in GitHub Desktop.
tornado-celery demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
import tornado.web | |
import tasks | |
class AppHandler(tornado.web.RequestHandler): | |
def get(self): | |
self.write("test app") | |
class MainHandler(tornado.web.RequestHandler): | |
@tornado.web.asynchronous | |
def get(self): | |
result = tasks.s.delay("hello world") | |
tornado.ioloop.IOLoop.instance().add_callback(self.on_result, result, callback) | |
self.write("Hello, world") | |
def on_result(self, result, callback): | |
if result.ready(): | |
callback(result.result) | |
self.finish() | |
else: | |
tornado.ioloop.IOLoop.instance().add_callback(self.on_result, result, callback) | |
def callback(s): | |
print s | |
if __name__ == "__main__": | |
application = tornado.web.Application([ | |
(r"/", MainHandler), | |
(r"/app", AppHandler), | |
]) | |
application.listen(8001) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment