这是一个非阻塞的,单线程的httpserver。这个类通常是不会被应用程序直接调用的,它通常是被上层的tornado.web.Application.listen方法调用,由于这个listen方法是这样定义的python
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,实例方法的区别
web
@classmethod 是一个函数修饰符,它表示接下来的是一个类方法,而对于日常咱们见到的则叫作实例方法。 类方法的第一个参数cls,而实例方法的第一个参数是self,表示该类的一个实例。由于持有cls参数,能够来调用类的属性,类的方法,实例化对象等,避免硬编码。app
静态方法则没有,它基本上跟一个全局函数相同,通常来讲用的不多,只是包含在类结构中,实际跟类没有关系,要调用到这个类的一些属性方法,只能直接类名.属性名或类名.方法名。函数
版本4.0的变化tornado
HTTPRequest类被移动到了tornado.httputil.HTTPServerRequest,原来的名字仍是能够使用的oop
HTTpServer默认支持keep-alive链接,自动支持HTTP/1.1,当客户端要求keep-alive链接时变为HTTP/1.0
this