Created
August 27, 2013 08:38
-
-
Save mayflaver/6351134 to your computer and use it in GitHub Desktop.
tornado event/driven 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 | |
class MainHandler(tornado.web.RequestHandler): | |
def get(self): | |
def test1(): | |
print 'test1' | |
def test2(): | |
print 'test2' | |
tornado.ioloop.IOLoop.instance().add_listener('test', test1) | |
tornado.ioloop.IOLoop.instance().add_listener('test', test2) | |
tornado.ioloop.IOLoop.instance().emit('test') | |
self.write("Hello, world") | |
application = tornado.web.Application([ | |
(r"/", MainHandler), | |
]) | |
if __name__ == "__main__": | |
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