Skip to content

Instantly share code, notes, and snippets.

@mayflaver
Created August 27, 2013 08:38
Show Gist options
  • Save mayflaver/6351134 to your computer and use it in GitHub Desktop.
Save mayflaver/6351134 to your computer and use it in GitHub Desktop.
tornado event/driven demo
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