当前位置: 首页>>代码示例>>Python>>正文


Python tornado.httpserver方法代码示例

本文整理汇总了Python中tornado.httpserver方法的典型用法代码示例。如果您正苦于以下问题:Python tornado.httpserver方法的具体用法?Python tornado.httpserver怎么用?Python tornado.httpserver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado的用法示例。


在下文中一共展示了tornado.httpserver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: listen

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpserver [as 别名]
def listen(self, port, address="", **kwargs):
        """为应用程序在给定端口上启动一个HTTP server.

        这是一个方便的别名用来创建一个 `.HTTPServer` 对象并调用它
        的listen方法. `HTTPServer.listen <.TCPServer.listen>`
        不支持传递关键字参数给 `.HTTPServer` 构造器. 对于高级用途
        (e.g. 多进程模式), 不要使用这个方法; 创建一个
        `.HTTPServer` 并直接调用它的
        `.TCPServer.bind`/`.TCPServer.start` 方法.

        注意在调用这个方法之后你仍然需要调用
        ``IOLoop.current().start()`` 来启动该服务.

        返回 `.HTTPServer` 对象.

        .. versionchanged:: 4.3
           现在返回 `.HTTPServer` 对象.
        """
        # 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 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:26,代码来源:web.py

示例2: listen

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpserver [as 别名]
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.instance().start()`` to start the server.
        """
        # 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) 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:21,代码来源:web.py

示例3: listen

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpserver [as 别名]
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 
开发者ID:tp4a,项目名称:teleport,代码行数:27,代码来源:web.py

示例4: listen

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpserver [as 别名]
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 are passed to the HTTPServer
        constructor.  For advanced uses (e.g. preforking), do not use
        this method; create an HTTPServer and call its bind/start
        methods directly.

        Note that after calling this method you still need to call
        IOLoop.instance().start() to start the server.
        """
        # 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) 
开发者ID:omererdem,项目名称:honeything,代码行数:20,代码来源:web.py

示例5: http_server

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpserver [as 别名]
def http_server(request, io_loop, _unused_port):
    """Start a tornado HTTP server.

    You must create an `app` fixture, which returns
    the `tornado.web.Application` to be tested.

    Raises:
        FixtureLookupError: tornado application fixture not found
    """
    http_app = request.getfixturevalue(request.config.option.app_fixture)
    server = tornado.httpserver.HTTPServer(http_app)
    server.add_socket(_unused_port[0])

    def _stop():
        server.stop()

        if hasattr(server, 'close_all_connections'):
            io_loop.run_sync(server.close_all_connections,
                             timeout=request.config.option.async_test_timeout)

    request.addfinalizer(_stop)
    return server 
开发者ID:eugeniy,项目名称:pytest-tornado,代码行数:24,代码来源:plugin.py

示例6: https_server

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpserver [as 别名]
def https_server(request, io_loop, _unused_port):
    """Start a tornado HTTPS server.

    You must create an `app` fixture, which returns
    the `tornado.web.Application` to be tested.

    Raises:
        FixtureLookupError: tornado application fixture not found
    """
    https_app = request.getfixturevalue(request.config.option.app_fixture)
    ssl_options = request.getfixturevalue(request.config.option.ssl_options_fixture)
    server = tornado.httpserver.HTTPServer(https_app, ssl_options=ssl_options)
    server.add_socket(_unused_port[0])

    def _stop():
        server.stop()

        if hasattr(server, 'close_all_connections'):
            io_loop.run_sync(server.close_all_connections,
                             timeout=request.config.option.async_test_timeout)

    request.addfinalizer(_stop)
    return server 
开发者ID:eugeniy,项目名称:pytest-tornado,代码行数:25,代码来源:plugin.py

示例7: shutdown

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpserver [as 别名]
def shutdown(ioloop, server):
    ''' 关闭server

    :param server: tornado.httpserver.HTTPServer
    '''
    logging.info(
        "HTTP interpreter service will shutdown in %ss...", 1)
    server.stop()

    deadline = time.time() + 1

    def stop_loop():
        ''' 尝试关闭loop
        '''
        now = time.time()
        if now < deadline and (ioloop._callbacks or ioloop._timeouts):
            ioloop.add_timeout(now + 1, stop_loop)
        else:
            # 处理完现有的 callback 和 timeout 后
            ioloop.stop()
            logging.info('Shutdown!')

    stop_loop() 
开发者ID:JK-River,项目名称:RobotAIEngine,代码行数:25,代码来源:init.py

示例8: main

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpserver [as 别名]
def main():
    ''' main 函数
    '''
    # 开启 search_engin_server
    ioloop = tornado.ioloop.IOLoop.instance()
    server = tornado.httpserver.HTTPServer(Application(), xheaders=True)
    server.listen(options.port)

    def sig_handler(sig, _):
        ''' 信号接收函数
        '''
        logging.warn("Caught signal: %s", sig)
        shutdown(ioloop, server)

    signal.signal(signal.SIGTERM, sig_handler)
    signal.signal(signal.SIGINT, sig_handler)
    ioloop.start() 
开发者ID:JK-River,项目名称:RobotAIEngine,代码行数:19,代码来源:init.py

示例9: cookies

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpserver [as 别名]
def cookies(self):
        """An alias for `self.request.cookies <.httpserver.HTTPRequest.cookies>`."""
        return self.request.cookies 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:5,代码来源:web.py

示例10: run_wsgi

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpserver [as 别名]
def run_wsgi(wsgi_app, port):
    """Runs wsgi (Flask) app using tornado web server."""

    container = tornado.wsgi.WSGIContainer(wsgi_app)
    app = tornado.web.Application([
        (r'.*', tornado.web.FallbackHandler, dict(fallback=container)),
    ])

    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(port)
    tornado.ioloop.IOLoop.instance().start() 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:13,代码来源:webutils.py

示例11: run_wsgi_unix

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpserver [as 别名]
def run_wsgi_unix(wsgi_app, socket):
    """Runs wsgi (Flask) app using tornado unixsocket web server."""

    container = tornado.wsgi.WSGIContainer(wsgi_app)
    app = tornado.web.Application([
        (r'.*', tornado.web.FallbackHandler, dict(fallback=container)),
    ])

    http_server = tornado.httpserver.HTTPServer(app)
    unix_socket = tornado.netutil.bind_unix_socket(socket)
    http_server.add_socket(unix_socket)
    tornado.ioloop.IOLoop.instance().start() 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:14,代码来源:webutils.py

示例12: main

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpserver [as 别名]
def main():
    tornado.options.parse_command_line()
    application = tornado.web.Application([
        (r"/", MainHandler),
    ])
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start() 
开发者ID:omererdem,项目名称:honeything,代码行数:10,代码来源:helloworld.py

示例13: start

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpserver [as 别名]
def start(self, port=None, timeout=1):
    """Starts a server in a thread using the WSGI application provided.

    Will wait until the thread has started calling with an already serving
    application will simple return.

    Args:
      port: Number of the port to use for the application, will find an open
        port if a nonzero port is not provided.
      timeout: Http timeout in seconds. Note that this is only respected under
        tornado v4.

    Raises:
      RuntimeError: if server is already started.
    """
    if self._server_thread is not None:
      raise RuntimeError('start() called on running background server.')

    self._port = port or portpicker.pick_unused_port()

    # Support both internal & external colab (tornado v3 vs. v4)
    # TODO(b/35548011): remove tornado v3 handling
    if tornado.version[0] >= '4':
      kwds = {'idle_connection_timeout': timeout, 'body_timeout': timeout}
    else:
      kwds = {}
    self._server = tornado.httpserver.HTTPServer(self._app, **kwds)
    self._ioloop = tornado.ioloop.IOLoop()

    def start_server(httpd, ioloop, port):
      # TODO(b/147233568): Restrict this to local connections.
      host = ''  # Bind to all
      ioloop.make_current()
      httpd.listen(port=port, address=host)
      ioloop.start()

    self._server_thread = threading.Thread(
        target=start_server,
        kwargs={
            'httpd': self._server,
            'ioloop': self._ioloop,
            'port': self._port
        })
    started = threading.Event()
    self._ioloop.add_callback(started.set)
    self._server_thread.start()
    started.wait() 
开发者ID:googlecolab,项目名称:colabtools,代码行数:49,代码来源:_background_server.py

示例14: run

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpserver [as 别名]
def run(self):
        self.ioloop = IOLoop.instance()
        self.alive = True
        PeriodicCallback(self.watchdog, 1000, io_loop=self.ioloop).start()

        # Assume the app is a WSGI callable if its not an
        # instance of tornado.web.Application or is an
        # instance of tornado.wsgi.WSGIApplication
        app = self.wsgi
        if not isinstance(app, tornado.web.Application) or \
           isinstance(app, tornado.wsgi.WSGIApplication):
            app = WSGIContainer(app)

        # Monkey-patching HTTPConnection.finish to count the
        # number of requests being handled by Tornado. This
        # will help gunicorn shutdown the worker if max_requests
        # is exceeded.
        httpserver = sys.modules["tornado.httpserver"]
        if hasattr(httpserver, 'HTTPConnection'):
            old_connection_finish = httpserver.HTTPConnection.finish

            def finish(other):
                self.handle_request()
                old_connection_finish(other)
            httpserver.HTTPConnection.finish = finish
            sys.modules["tornado.httpserver"] = httpserver

            server_class = tornado.httpserver.HTTPServer
        else:

            class _HTTPServer(tornado.httpserver.HTTPServer):

                def on_close(instance, server_conn):
                    self.handle_request()
                    super(_HTTPServer, instance).on_close(server_conn)

            server_class = _HTTPServer

        if self.cfg.is_ssl:
            server = server_class(app, io_loop=self.ioloop,
                    ssl_options=self.cfg.ssl_options)
        else:
            server = server_class(app, io_loop=self.ioloop)

        self.server = server

        for s in self.sockets:
            s.setblocking(0)
            if hasattr(server, "add_socket"):  # tornado > 2.0
                server.add_socket(s)
            elif hasattr(server, "_sockets"):  # tornado 2.0
                server._sockets[s.fileno()] = s

        server.no_keep_alive = self.cfg.keepalive <= 0
        server.start(num_processes=1)

        self.ioloop.start() 
开发者ID:chalasr,项目名称:Flask-P2P,代码行数:59,代码来源:gtornado.py

示例15: main

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import httpserver [as 别名]
def main():
    define(name='port', default=8000, type=int, help='run on the given port')
    parse_command_line()
    logger.info('====== web server starting at http://0.0.0.0:{} ======'.format(options.port))
    if constants.DEBUG:
        logger.info('debug mode is enabled!!!')

    app = make_web_app()
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port)
    http_server.start()

    tornado.ioloop.IOLoop.instance().start() 
开发者ID:JustForFunnnn,项目名称:webspider,代码行数:15,代码来源:app.py


注:本文中的tornado.httpserver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。