安装
pip install tornado
第一个程序
from tornado import web
from tornado import ioloop
class IndexHandler(web.RequestHandler):
def get(self):
self.write('Hello Tornado!!123')
if __name__ == '__main__':
app = web.Application([('/', IndexHandler)], debug=True)
app.listen(8000)
ioloop.IOLoop.current().start()
程序的原理
不能使用同步代码的演示
from tornado import web
from tornado import ioloop
from time import sleep
class IndexHandler(web.RequestHandler):
def get(self):
sleep(5)
self.write('Hello Tornado!!')
class IndexHandler2(web.RequestHandler):
def get(self):
self.write('Hello Tornado!!你好')
if __name__ == '__main__':
app = web.Application([
('/', IndexHandler),
('/index/', IndexHandler2),
], debug=True)
app.listen(8000)
ioloop.IOLoop.current().start()