Created
May 11, 2015 17:35
-
-
Save SeavantUUz/38b8ca113c5455890d59 to your computer and use it in GitHub Desktop.
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
# 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