Skip to content

Instantly share code, notes, and snippets.

@SeavantUUz
Created May 11, 2015 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeavantUUz/38b8ca113c5455890d59 to your computer and use it in GitHub Desktop.
Save SeavantUUz/38b8ca113c5455890d59 to your computer and use it in GitHub Desktop.
# coding: utf-8
from tornado.ioloop import IOLoop
import tornado.web
from tornado import gen
import time
import settings as Settings
class TestHandler(tornado.web.RequestHandler):
@gen.coroutine
def get(self):
print 'test'
self.set_header('Content-Type', 'text/event-stream')
self.set_header('Cache-Control', 'no-cache')
self.write('hello world')
self.flush()
yield gen.Task(IOLoop.instance().add_timeout, time.time() + 5)
self.write('other info')
self.write('hahaha')
yield gen.Task(IOLoop.instance().add_timeout, time.time() + 2)
self.finish()
class MainHandler(tornado.web.RequestHandler):
@gen.coroutine
def get(self):
print 'get'
self.render('template.html')
application = tornado.web.Application([
(r'/', MainHandler),
(r"/test", TestHandler),
], template_path=Settings.TEMPLATE_PATH)
if __name__ == '__main__':
application.listen(8888)
IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment