• tornado httpserver


    这是一个非阻塞的,单线程的httpserver。这个类一般是不会被应用程序直接调用的,它一般是被上层的tornado.web.Application.listen方法调用,因为这个listen方法是这样定义的

     def listen(self, port, address="", **kwargs):
            """Starts an HTTP server for this application on the given port.
    
            This is a convenience alias for creating an `.HTTPServer`
            object and calling its listen method.  Keyword arguments not
            supported by `HTTPServer.listen <.TCPServer.listen>` are passed to the
            `.HTTPServer` constructor.  For advanced uses
            (e.g. multi-process mode), do not use this method; create an
            `.HTTPServer` and call its
            `.TCPServer.bind`/`.TCPServer.start` methods directly.
    
            Note that after calling this method you still need to call
            ``IOLoop.current().start()`` to start the server.
    
            Returns the `.HTTPServer` object.
    
            .. versionchanged:: 4.3
               Now returns the `.HTTPServer` object.
            """
            # import is here rather than top level because HTTPServer
            # is not importable on appengine
            from tornado.httpserver import HTTPServer
            server = HTTPServer(self, **kwargs)
            server.listen(port, address)
            return server

    @staticmethod和@classmethod,实例方法的区别

    @classmethod 是一个函数修饰符,它表示接下来的是一个类方法,而对于平常我们见到的则叫做实例方法。 类方法的第一个参数cls,而实例方法的第一个参数是self,表示该类的一个实例。因为持有cls参数,可以来调用类的属性,类的方法,实例化对象等,避免硬编码。

    静态方法则没有,它基本上跟一个全局函数相同,一般来说用的很少,只是包含在类结构中,实际跟类没有关系,要调用到这个类的一些属性方法,只能直接类名.属性名或类名.方法名。

    版本4.0的变化

    HTTPRequest类被移动到了tornado.httputil.HTTPServerRequest,原来的名字还是可以使用的

    HTTpServer默认支持keep-alive连接,自动支持HTTP/1.1,当客户端要求keep-alive连接时变为HTTP/1.0

  • 相关阅读:
    Jedis与Redisson选型对比
    使用rdbtools工具来解析redis rdb文件
    Generating equals/hashCode implementation but without a call to superclass
    解决 Order By 将字符串类型的数字 或 字符串中含数字 按数字排序问题
    File.delete()和Files.delete(Path path)的区别
    file.deleteOnExit()与file.delete()的区别
    java日期中YYYY与yyyy的区别
    IDEA git分支回退指定的历史版本
    Lucene介绍与使用
    Lombok 学习指南
  • 原文地址:https://www.cnblogs.com/suntp/p/6616029.html
Copyright © 2020-2023  润新知