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


Python serving.make_server方法代码示例

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


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

示例1: start

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import make_server [as 别名]
def start(self):
        """
        Start the server in a thread.

        This method returns immediately (e.g. does not block), and it's the caller's
        responsibility to stop the server (by calling :py:meth:`stop`) when it is no longer needed).

        If the sever is not stopped by the caller and execution reaches the end, the
        program needs to be terminated by Ctrl+C or by signal as it will not terminate until
        the thred is stopped.

        If the sever is already running :py:class:`HTTPServerError` will be raised. If you are
        unsure, call :py:meth:`is_running` first.

        There's a context interface of this class which stops the server when the context block ends.
        """
        if self.is_running():
            raise HTTPServerError("Server is already running")

        self.server = make_server(self.host, self.port, self.application, ssl_context=self.ssl_context)
        self.port = self.server.port  # Update port (needed if `port` was set to 0)
        self.server_thread = threading.Thread(target=self.thread_target)
        self.server_thread.start() 
开发者ID:csernazs,项目名称:pytest-httpserver,代码行数:25,代码来源:httpserver.py

示例2: __init__

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import make_server [as 别名]
def __init__(self, config):
        """Create Flask based web service."""
        self.config = config
        data_dir = None
        if config:
            data_dir = config.get('data_dir', None)
        if not data_dir:
            data_dir = DEFAULT_DATA_DIR
        self.srv = None
        app = create_app(data_dir=data_dir)
        ip_address = '0.0.0.0'
        port = 8778
        log.info('starting flask web server on %s:%d', ip_address, port)
        self.srv = make_server(ip_address, port, app)
        ctx = app.app_context()
        ctx.push()
        with app.app_context():
            flask.current_app.data_dir = data_dir
        self.flask_stopped = True
        log.debug('Flask process created') 
开发者ID:ambianic,项目名称:ambianic-edge,代码行数:22,代码来源:flaskr.py

示例3: init_werkzeug_server

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import make_server [as 别名]
def init_werkzeug_server(app, port, host):
    try:
        import werkzeug
    except ImportError:
        raise ImportError(
            'Capybara\'s werkzeug server is unable to load `werkzeug`, please install the package '
            'and add `werkzeug` to your requirements.txt file.')

    from werkzeug.serving import make_server
    from logging import getLogger

    # Mute the server.
    log = getLogger('werkzeug')
    log.disabled = True

    server = make_server(host, port, app, threaded=True)

    # Inform Python that it shouldn't wait for request threads to terminate before
    # exiting. (They will still be appropriately terminated when the process exits.)
    server.daemon_threads = True

    server.serve_forever() 
开发者ID:elliterate,项目名称:capybara.py,代码行数:24,代码来源:__init__.py

示例4: make_server

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import make_server [as 别名]
def make_server(host, port, app, logging=True):
    if host is None:
        raise RuntimeError("host cannot be None")
    if port is None:
        raise RuntimeError("port cannot be None")
    if logging:
        request_handler = serving.WSGIRequestHandler
    else:
        request_handler = QuietRequestHandler
    try:
        return serving.make_server(
            host, port, app, threaded=True, request_handler=request_handler
        )
    except socket.error as e:
        if host:
            raise
        log.debug(
            "error starting server on %s:%s (%s), " "trying IPv6 default host '::'",
            host,
            port,
            e,
        )
        return serving.make_server("::", port, app, threaded=True) 
开发者ID:guildai,项目名称:guildai,代码行数:25,代码来源:serving_util.py

示例5: run_dev_server

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import make_server [as 别名]
def run_dev_server(application):
    servers = []

    def tracking_make_server(*args, **kwargs):
        srv = real_make_server(*args, **kwargs)
        servers.append(srv)
        return srv
    serving.make_server = tracking_make_server
    try:
        t = Thread(target=serving.run_simple,
                   args=('localhost', 0, application))
        t.setDaemon(True)
        t.start()
        time.sleep(0.25)
    finally:
        serving.make_server = real_make_server
    if not servers:
        return None, None
    server, = servers
    ip, port = server.socket.getsockname()[:2]
    if ':' in ip:
        ip = '[%s]' % ip
    return server, '%s:%d'  % (ip, port) 
开发者ID:GeekTrainer,项目名称:Flask,代码行数:25,代码来源:serving.py

示例6: __init__

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import make_server [as 别名]
def __init__(self, folder_name, host="127.0.0.1", verbosity=logging.WARN):
        Thread.__init__(self)
        self.project_key = os.environ["DKU_CURRENT_PROJECT_KEY"]
        self.folder_name = folder_name
        self.client = dataiku.api_client()

        logging.set_verbosity(verbosity)

        # Getting app
        logs_path = self.__get_logs_path()
        app = self.__get_tb_app(logs_path)

        # Setting server
        self.srv = make_server(host, 0, app) 
开发者ID:dataiku,项目名称:dataiku-contrib,代码行数:16,代码来源:tensorboard_handle.py

示例7: run

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import make_server [as 别名]
def run(self, host, port, middleware=None):
        """Werkzeug run implementation.

        `middleware` may be provided as a function to handle
        requests. It must accept the arguments `(handler, req)` where
        `handler` is the TFServeApp request handler and `req` is the
        request.

        """
        app = self._init_app(middleware)
        server = serving.make_server(
            host, port, app, threaded=True,
            request_handler=serving.WSGIRequestHandler)
        server.serve_forever() 
开发者ID:iitzco,项目名称:tfserve,代码行数:16,代码来源:tfserve.py

示例8: __init__

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import make_server [as 别名]
def __init__(self, *, host, port):
        self.host = host
        self.port = port
        self.app = flask.Flask('test')
        self.app.url_map.converters['everything'] = EverythingConverter

        self.srv = make_server(host=self.host, port=self.port, app=self.app)
        self.server_thread = threading.Thread(target=self.run, daemon=True) 
开发者ID:serathius,项目名称:sanic-sentry,代码行数:10,代码来源:tests.py

示例9: make_simple_server

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import make_server [as 别名]
def make_simple_server(app, host, port):
    server = serving.make_server(host, port, app, threaded=True)
    server.daemon_threads = True
    server.handle_error = _handle_error
    tensorboard_url = "http://%s:%s" % (host, port)
    return server, tensorboard_url 
开发者ID:guildai,项目名称:guildai,代码行数:8,代码来源:tensorboard.py

示例10: make_simple_server

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import make_server [as 别名]
def make_simple_server(tb_app, host, port):
  """Create an HTTP server for TensorBoard.

  Args:
    tb_app: The TensorBoard WSGI application to create a server for.
    host: Indicates the interfaces to bind to ('::' or '0.0.0.0' for all
        interfaces, '::1' or '127.0.0.1' for localhost). A blank value ('')
        indicates protocol-agnostic all interfaces.
    port: The port to bind to (0 indicates an unused port selected by the
        operating system).
  Returns:
    A tuple of (server, url):
      server: An HTTP server object configured to host TensorBoard.
      url: A best guess at a URL where TensorBoard will be accessible once the
        server has been started.
  Raises:
    socket.error: If a server could not be constructed with the host and port
      specified. Also logs an error message.
  """
  # Mute the werkzeug logging.
  base_logging.getLogger('werkzeug').setLevel(base_logging.WARNING)

  try:
    if host:
      # The user gave us an explicit host
      server = serving.make_server(host, port, tb_app, threaded=True)
      if ':' in host and not host.startswith('['):
        # Display IPv6 addresses as [::1]:80 rather than ::1:80
        final_host = '[{}]'.format(host)
      else:
        final_host = host
    else:
      # We've promised to bind to all interfaces on this host. However, we're
      # not sure whether that means IPv4 or IPv6 interfaces.
      try:
        # First try passing in a blank host (meaning all interfaces). This,
        # unfortunately, defaults to IPv4 even if no IPv4 interface is available
        # (yielding a socket.error).
        server = serving.make_server(host, port, tb_app, threaded=True)
      except socket.error:
        # If a blank host didn't work, we explicitly request IPv6 interfaces.
        server = serving.make_server('::', port, tb_app, threaded=True)
      final_host = socket.gethostname()
    server.daemon_threads = True
  except socket.error as socket_error:
    if port == 0:
      msg = 'TensorBoard unable to find any open port'
    else:
      msg = (
          'TensorBoard attempted to bind to port %d, but it was already in use'
          % FLAGS.port)
    logging.error(msg)
    print(msg)
    raise socket_error

  final_port = server.socket.getsockname()[1]
  tensorboard_url = 'http://%s:%d' % (final_host, final_port)
  return server, tensorboard_url 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:60,代码来源:tensorboard.py

示例11: make_simple_server

# 需要导入模块: from werkzeug import serving [as 别名]
# 或者: from werkzeug.serving import make_server [as 别名]
def make_simple_server(tb_app, host, port):
  """Create an HTTP server for TensorBoard.

  Args:
    tb_app: The TensorBoard WSGI application to create a server for.
    host: Indicates the interfaces to bind to ('::' or '0.0.0.0' for all
        interfaces, '::1' or '127.0.0.1' for localhost). A blank value ('')
        indicates protocol-agnostic all interfaces.
    port: The port to bind to (0 indicates an unused port selected by the
        operating system).
  Returns:
    A tuple of (server, url):
      server: An HTTP server object configured to host TensorBoard.
      url: A best guess at a URL where TensorBoard will be accessible once the
        server has been started.
  Raises:
    socket.error: If a server could not be constructed with the host and port
      specified. Also logs an error message.
  """
  # Mute the werkzeug logging.
  base_logging.getLogger('werkzeug').setLevel(base_logging.WARNING)

  try:
    if host:
      # The user gave us an explicit host
      server = serving.make_server(host, port, tb_app, threaded=True)
      if ':' in host and not host.startswith('['):
        # Display IPv6 addresses as [::1]:80 rather than ::1:80
        final_host = '[{}]'.format(host)
      else:
        final_host = host
    else:
      # We've promised to bind to all interfaces on this host. However, we're
      # not sure whether that means IPv4 or IPv6 interfaces.
      try:
        # First try passing in a blank host (meaning all interfaces). This,
        # unfortunately, defaults to IPv4 even if no IPv4 interface is available
        # (yielding a socket.error).
        server = serving.make_server(host, port, tb_app, threaded=True)
      except socket.error:
        # If a blank host didn't work, we explicitly request IPv6 interfaces.
        server = serving.make_server('::', port, tb_app, threaded=True)
      final_host = socket.gethostname()
    server.daemon_threads = True
  except socket.error as socket_error:
    if port == 0:
      msg = 'TensorBoard unable to find any open port'
    else:
      msg = (
          'TensorBoard attempted to bind to port %d, but it was already in use'
          % port)
    logging.error(msg)
    print(msg)
    raise socket_error

  final_port = server.socket.getsockname()[1]
  tensorboard_url = 'http://%s:%d' % (final_host, final_port)
  return server, tensorboard_url 
开发者ID:tensorlang,项目名称:tensorlang,代码行数:60,代码来源:tensorboard_server.py


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