mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
update longpoll examples
Add a longpoll example for tornado and terminate the lines we send with a '\n'.
This commit is contained in:
parent
b955407003
commit
f02b0d9cca
@ -8,13 +8,32 @@
|
||||
# $ gunicorn -k egg:gunicorn#tornado tornadoapp:app
|
||||
#
|
||||
|
||||
import tornado.web
|
||||
from datetime import timedelta
|
||||
|
||||
class MainHandler(tornado.web.RequestHandler):
|
||||
from tornado.web import Application, RequestHandler, asynchronous
|
||||
from tornado.ioloop import IOLoop
|
||||
|
||||
class MainHandler(RequestHandler):
|
||||
def get(self):
|
||||
self.write("Hello, world")
|
||||
|
||||
app = tornado.web.Application([
|
||||
(r"/", MainHandler)
|
||||
class LongPollHandler(RequestHandler):
|
||||
@asynchronous
|
||||
def get(self):
|
||||
lines = ['line 1\n', 'line 2\n']
|
||||
|
||||
def send():
|
||||
try:
|
||||
self.write(lines.pop(0))
|
||||
self.flush()
|
||||
except:
|
||||
self.finish()
|
||||
else:
|
||||
IOLoop.instance().add_timeout(timedelta(0, 20), send)
|
||||
send()
|
||||
|
||||
app = Application([
|
||||
(r"/", MainHandler),
|
||||
(r"/longpoll", LongPollHandler)
|
||||
])
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ import time
|
||||
class TestIter(object):
|
||||
|
||||
def __iter__(self):
|
||||
lines = ['line 1', 'line 2']
|
||||
lines = ['line 1\n', 'line 2\n']
|
||||
for line in lines:
|
||||
yield line
|
||||
time.sleep(20)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user