# 开启循环,让服务一直等待请求的到来
import tornado.ioloop
# web 服务基本功能都封装在此模块中
import tornado.web
from tornado.web import RequestHandler
import tornado.options
from tornado.options import define, options
import tornado.httpserver
# 指定默认端口
define('port', default=8000, help='run port', type=int)
class MainHandler(RequestHandler):
"""
指定请求的资源
"""
def get(self):
self.write('hello world')
class Application(tornado.web.Application):
def __init__(self):
handlers = [
(r'/', MainHandler)
]
settings = dict(
debug=True
)
super(Application, self).__init__(handlers, **settings)
app = Application()
if __name__ == "__main__":
tornado.options.parse_command_line()
print('端口是', options.port)
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
tornado服务
最新推荐文章于 2022-03-08 21:05:31 发布