mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Update tornadoapp.py
This commit is contained in:
parent
7f559886cb
commit
5e39f88622
@ -8,31 +8,23 @@
|
|||||||
# $ gunicorn -k tornado tornadoapp:app
|
# $ gunicorn -k tornado tornadoapp:app
|
||||||
#
|
#
|
||||||
|
|
||||||
from datetime import timedelta
|
import tornado.ioloop
|
||||||
|
import tornado.web
|
||||||
|
from tornado import gen
|
||||||
|
|
||||||
from tornado.web import Application, RequestHandler, asynchronous
|
class MainHandler(tornado.web.RequestHandler):
|
||||||
from tornado.ioloop import IOLoop
|
@gen.coroutine
|
||||||
|
|
||||||
class MainHandler(RequestHandler):
|
|
||||||
def get(self):
|
def get(self):
|
||||||
self.write("Hello, world")
|
# Your asynchronous code here
|
||||||
|
yield gen.sleep(1) # Example of an asynchronous operation
|
||||||
|
self.write("Hello, World!")
|
||||||
|
|
||||||
class LongPollHandler(RequestHandler):
|
def make_app():
|
||||||
@asynchronous
|
return tornado.web.Application([
|
||||||
def get(self):
|
(r"/", MainHandler),
|
||||||
lines = ['line 1\n', 'line 2\n']
|
])
|
||||||
|
|
||||||
def send():
|
if __name__ == "__main__":
|
||||||
try:
|
app = make_app()
|
||||||
self.write(lines.pop(0))
|
app.listen(8888)
|
||||||
self.flush()
|
tornado.ioloop.IOLoop.current().start()
|
||||||
except:
|
|
||||||
self.finish()
|
|
||||||
else:
|
|
||||||
IOLoop.instance().add_timeout(timedelta(0, 20), send)
|
|
||||||
send()
|
|
||||||
|
|
||||||
app = Application([
|
|
||||||
(r"/", MainHandler),
|
|
||||||
(r"/longpoll", LongPollHandler)
|
|
||||||
])
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user