Tornado—options.define()方法与options.options解读

我是研究僧i 提交于 2019-12-10 18:46:45

https://www.cnblogs.com/renfanzi/p/9585167.html

https://www.jianshu.com/p/ec17650059c9

# -*- coding:utf-8 -*-

import tornado.web         # web服务
import tornado.ioloop      # I/O 时间循环
import tornado.httpserver  # 新引入httpserver模块,单线程的http服务
from tornado.options import define, options

define("ip", default="", help="run on the given ip", type=str)
define("port", default=8066, type=int, help="run on the given port")
define("domain", default=[], type=str, help="run on the given domain", multiple=True)

class Mainhandler(tornado.web.RequestHandler):
    def get(self):
        self.write("hello world!")

app = tornado.web.Application([
        (r"/index", Mainhandler),
    ])

if __name__ == "__main__":
    # 如果命令行没有传值,则使用默认值
    # tornado.options.parse_command_line()
    tornado.options.parse_config_file(path)
    # print tornado.options.options  # 输出多值选项

    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port)
    # tornado.ioloop.IOLoop.current().start()
    tornado.ioloop.IOLoop.instance().start()

  

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!