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


Python portpicker.pick_unused_port方法代码示例

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


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

示例1: create_local_cluster

# 需要导入模块: import portpicker [as 别名]
# 或者: from portpicker import pick_unused_port [as 别名]
def create_local_cluster(num_workers, num_ps, protocol="grpc"):
  """Create local GRPC servers and return them."""
  worker_ports = [portpicker.pick_unused_port() for _ in range(num_workers)]
  ps_ports = [portpicker.pick_unused_port() for _ in range(num_ps)]
  cluster_dict = {
      "worker": ["localhost:%s" % port for port in worker_ports],
      "ps": ["localhost:%s" % port for port in ps_ports]}
  cs = tf.train.ClusterSpec(cluster_dict)

  workers = [
      tf.train.Server(
          cs, job_name="worker", protocol=protocol, task_index=ix, start=True)
      for ix in range(num_workers)]
  ps_servers = [
      tf.train.Server(
          cs, job_name="ps", protocol=protocol, task_index=ix, start=True)
      for ix in range(num_ps)]

  return workers, ps_servers


# Creates the workers and return their sessions, graphs, train_ops. 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:24,代码来源:sync_replicas_optimizer_test.py

示例2: create_local_cluster

# 需要导入模块: import portpicker [as 别名]
# 或者: from portpicker import pick_unused_port [as 别名]
def create_local_cluster(num_workers, num_ps, protocol="grpc"):
  """Create local GRPC servers and return their servers."""
  worker_ports = [portpicker.pick_unused_port() for _ in range(num_workers)]
  ps_ports = [portpicker.pick_unused_port() for _ in range(num_ps)]
  cluster_dict = {
      "worker": ["localhost:%s" % port for port in worker_ports],
      "ps": ["localhost:%s" % port for port in ps_ports]}
  cs = tf.train.ClusterSpec(cluster_dict)

  workers = [
      tf.train.Server(
          cs, job_name="worker", protocol=protocol, task_index=ix, start=True)
      for ix in range(num_workers)]
  ps_servers = [
      tf.train.Server(
          cs, job_name="ps", protocol=protocol, task_index=ix, start=True)
      for ix in range(num_ps)]

  return workers, ps_servers 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:21,代码来源:localhost_cluster_performance_test.py

示例3: pick_unused_ports

# 需要导入模块: import portpicker [as 别名]
# 或者: from portpicker import pick_unused_port [as 别名]
def pick_unused_ports(num_ports, retry_interval_secs=1, retry_attempts=5):
  """Reserves and returns a list of `num_ports` unused ports."""
  if num_ports <= 0:
    raise ValueError("Number of ports, must be >= 1, got: %s" % num_ports)
  ports = set()
  for _ in range(retry_attempts):
    ports.update(
        portpicker.pick_unused_port() for _ in range(num_ports - len(ports)))
    ports.discard(None)  # portpicker returns None on error.
    if len(ports) == num_ports:
      return list(ports)
    # Duplicate ports can be returned, especially when insufficient ports are
    # free. Wait for more ports to be freed and retry.
    time.sleep(retry_interval_secs)

  # Could not obtain enough ports. Release what we do have.
  return_ports(ports)

  raise RuntimeError("Unable to obtain %d unused ports." % num_ports) 
开发者ID:deepmind,项目名称:pysc2,代码行数:21,代码来源:portspicker.py

示例4: pick_contiguous_unused_ports

# 需要导入模块: import portpicker [as 别名]
# 或者: from portpicker import pick_unused_port [as 别名]
def pick_contiguous_unused_ports(
    num_ports,
    retry_interval_secs=1,
    retry_attempts=5):
  """Reserves and returns a list of `num_ports` contiguous unused ports."""
  if num_ports <= 0:
    raise ValueError("Number of ports, must be >= 1, got: %s" % num_ports)
  for _ in range(retry_attempts):
    start_port = portpicker.pick_unused_port()
    if start_port is not None:
      ports = [start_port + p for p in range(num_ports)]
      if all(portpicker.is_port_free(p) for p in ports):
        _contiguous_ports.update(ports[1:])
        return ports
      else:
        portpicker.return_port(start_port)

    time.sleep(retry_interval_secs)

  raise RuntimeError("Unable to obtain %d contiguous unused ports." % num_ports) 
开发者ID:deepmind,项目名称:pysc2,代码行数:22,代码来源:portspicker.py

示例5: __init__

# 需要导入模块: import portpicker [as 别名]
# 或者: from portpicker import pick_unused_port [as 别名]
def __init__(self, host: str = "127.0.0.1", port: Optional[int] = None, fullscreen: bool = False,
                 render: bool = False) -> None:
        assert isinstance(host, str)
        assert isinstance(port, int) or port is None

        self._render = render
        self._fullscreen = fullscreen
        self._host = host
        if port is None:
            self._port = portpicker.pick_unused_port()
        else:
            self._port = port
        self._tmp_dir = tempfile.mkdtemp(prefix="SC2_")
        self._process = None
        self._session = None
        self._ws = None 
开发者ID:Dentosal,项目名称:python-sc2,代码行数:18,代码来源:sc2process.py

示例6: setUp

# 需要导入模块: import portpicker [as 别名]
# 或者: from portpicker import pick_unused_port [as 别名]
def setUp(self):
    self._test_dir = tempfile.mkdtemp()
    self.assertIsNotNone(self._test_dir)
    self._server_port = portpicker.pick_unused_port()
    self._compilation_server_proc = subprocess.Popen(
      [os.path.join(
        os.environ["TEST_SRCDIR"],
        "__main__/freemindlatex/freemindlatex_app_main"),
        "--port",
       str(self._server_port),
       "server"])
    self._server_address = "127.0.0.1:{}".format(self._server_port)
    self._compilation_client = compilation_client_lib.LatexCompilationClient(
      self._server_address)

    compilation_client_lib.WaitTillHealthy(self._server_address)
    self.assertTrue(self._compilation_client.CheckHealthy()) 
开发者ID:xuehuichao,项目名称:freemind-latex,代码行数:19,代码来源:integration_test_lib.py

示例7: Launch

# 需要导入模块: import portpicker [as 别名]
# 或者: from portpicker import pick_unused_port [as 别名]
def Launch(debug: bool = False):
  """Launch dashboard in a separate thread."""
  port = FLAGS.clgen_dashboard_port or portpicker.pick_unused_port()
  app.Log(
    1, "Launching CLgen dashboard on http://127.0.0.1:%d", port,
  )
  kwargs = {
    "port": port,
    # Debugging must be disabled when run in a separate thread.
    "debug": debug,
    "host": "0.0.0.0",
  }

  db.create_all()
  if debug:
    flask_app.run(**kwargs)
  else:
    thread = threading.Thread(target=flask_app.run, kwargs=kwargs)
    thread.setDaemon(True)
    thread.start()
    return thread 
开发者ID:ChrisCummins,项目名称:clgen,代码行数:23,代码来源:dashboard.py

示例8: setUp

# 需要导入模块: import portpicker [as 别名]
# 或者: from portpicker import pick_unused_port [as 别名]
def setUp(self):
    with mock.patch.object(bidaf_server.BidafServer,
                           '_InitializeEnvironment') as mock_method:
      port = portpicker.pick_unused_port()
      server_pool = logging_pool.pool(max_workers=10)
      self._server = grpc.server(server_pool)
      self._server.add_insecure_port('[::]:{}'.format(port))
      servicer = bidaf_server.BidafServer('BidafServer', 'test BiDAF server')
      servicer._environment = MockBidafEnvironment()

      aqa_pb2_grpc.add_EnvironmentServerServicer_to_server(
          servicer, self._server)
      self._server.start()

      channel = grpc.insecure_channel('localhost:%d' % port)
      self._stub = aqa_pb2_grpc.EnvironmentServerStub(channel)

      mock_method.assert_called_once_with(
          model_dir=None,
          data_dir=None,
          debug_mode=False,
          load_test=False,
          load_impossible_questions=False,
          shared_file=None) 
开发者ID:google,项目名称:active-qa,代码行数:26,代码来源:bidaf_server_test.py

示例9: load_from_docker

# 需要导入模块: import portpicker [as 别名]
# 或者: from portpicker import pick_unused_port [as 别名]
def load_from_docker(settings, name=None):
  """Load Memory Tasks from docker container.

  Args:
    settings: EnvironmentSettings required to start the environment.
    name: Optional name of Docker image that contains the dm_memorytasks
      environment. If left unset, uses the dm_memorytasks default name.

  Returns:
    An implementation of dm_env.Environment
  """
  _validate_environment_settings(settings)

  name = name or _DEFAULT_DOCKER_IMAGE_NAME
  client = docker.from_env()

  port = portpicker.pick_unused_port()

  try:
    client.images.get(name)
  except docker.errors.ImageNotFound:
    logging.info('Downloading docker image "%s"...', name)
    client.images.pull(name)
    logging.info('Download finished.')

  container = client.containers.run(
      name,
      auto_remove=True,
      detach=True,
      ports={_DOCKER_INTERNAL_GRPC_PORT: port})

  return _MemoryTasksContainerEnv(
      _connect_to_environment(port, settings), _MEMORY_TASK_OBSERVATIONS,
      settings.num_action_repeats, container) 
开发者ID:deepmind,项目名称:dm_memorytasks,代码行数:36,代码来源:_load_environment.py

示例10: create_remote_executor

# 需要导入模块: import portpicker [as 别名]
# 或者: from portpicker import pick_unused_port [as 别名]
def create_remote_executor():
  port = portpicker.pick_unused_port()
  channel = grpc.insecure_channel('localhost:{}'.format(port))
  return remote_executor.RemoteExecutor(channel, 'REQUEST_REPLY') 
开发者ID:tensorflow,项目名称:federated,代码行数:6,代码来源:remote_executor_test.py

示例11: test_context

# 需要导入模块: import portpicker [as 别名]
# 或者: from portpicker import pick_unused_port [as 别名]
def test_context(rpc_mode='REQUEST_REPLY'):
  port = portpicker.pick_unused_port()
  server_pool = logging_pool.pool(max_workers=1)
  server = grpc.server(server_pool)
  server.add_insecure_port('[::]:{}'.format(port))
  target_executor = executor_stacks.local_executor_factory(
      num_clients=3).create_executor({})
  tracer = executor_test_utils.TracingExecutor(target_executor)
  service = executor_service.ExecutorService(tracer)
  executor_pb2_grpc.add_ExecutorServicer_to_server(service, server)
  server.start()
  channel = grpc.insecure_channel('localhost:{}'.format(port))
  remote_exec = remote_executor.RemoteExecutor(channel, rpc_mode)
  executor = reference_resolving_executor.ReferenceResolvingExecutor(
      remote_exec)
  try:
    yield collections.namedtuple('_', 'executor tracer')(executor, tracer)
  finally:
    executor.close()
    tracer.close()
    try:
      channel.close()
    except AttributeError:
      pass  # Public gRPC channel doesn't support close()
    finally:
      server.stop(None) 
开发者ID:tensorflow,项目名称:federated,代码行数:28,代码来源:remote_executor_test.py

示例12: __init__

# 需要导入模块: import portpicker [as 别名]
# 或者: from portpicker import pick_unused_port [as 别名]
def __init__(self, executor: executor_base.Executor):
    port = portpicker.pick_unused_port()
    server_pool = logging_pool.pool(max_workers=1)
    self._server = grpc.server(server_pool)
    self._server.add_insecure_port('[::]:{}'.format(port))
    self._service = executor_service.ExecutorService(executor)
    executor_pb2_grpc.add_ExecutorServicer_to_server(self._service,
                                                     self._server)
    self._server.start()
    self._channel = grpc.insecure_channel('localhost:{}'.format(port))
    self._stub = executor_pb2_grpc.ExecutorStub(self._channel) 
开发者ID:tensorflow,项目名称:federated,代码行数:13,代码来源:executor_service_test.py

示例13: getUnusedPort

# 需要导入模块: import portpicker [as 别名]
# 或者: from portpicker import pick_unused_port [as 别名]
def getUnusedPort():
  """Returns an unused TCP port on the local host inside the defined port range.
  To be used when starting peer SAS webserver or other database webserver.
  """
  config = _GetSharedTestConfig()
  if config.min_port < 0:
    return portpicker.pick_unused_port()
  global _ports
  # Find the first available port in the defined range.
  for p in xrange(config.min_port, config.max_port):
    if p not in _ports and portpicker.is_port_free(p):
      _ports.add(p)
      return p
  raise AssertionError('No available new ports') 
开发者ID:Wireless-Innovation-Forum,项目名称:Spectrum-Access-System,代码行数:16,代码来源:util.py

示例14: __init__

# 需要导入模块: import portpicker [as 别名]
# 或者: from portpicker import pick_unused_port [as 别名]
def __init__(self):
        self.shared = portpicker.pick_unused_port()
        self.server = [portpicker.pick_unused_port() for _ in range(2)]
        self.players = [[portpicker.pick_unused_port() for _ in range(2)] for _ in range(2)] 
开发者ID:Dentosal,项目名称:python-sc2,代码行数:6,代码来源:portconfig.py

示例15: mock_distribute

# 需要导入模块: import portpicker [as 别名]
# 或者: from portpicker import pick_unused_port [as 别名]
def mock_distribute(fn, num_workers=2):
    """Runs `fn` in multiple processes, setting appropriate env vars."""
    port = str(portpicker.pick_unused_port())
    with mock.patch.object(os, 'environ', MockEnvVars()):

        def chief_fn():
            # The IP address of the chief Oracle. Run in distributed mode when
            # present. Cloud oracle does not run in this mode because the Cloud
            # API coordinates workers itself.
            os.environ['KERASTUNER_ORACLE_IP'] = '127.0.0.1'
            # The port of the chief Oracle.
            os.environ['KERASTUNER_ORACLE_PORT'] = port
            # The ID of this process. 'chief' will run the OracleServicer server.
            os.environ['KERASTUNER_TUNER_ID'] = 'chief'
            fn()
        chief_thread = ExceptionStoringThread(target=chief_fn)
        chief_thread.daemon = True
        chief_thread.start()

        worker_threads = []
        for i in range(num_workers):

            def worker_fn():
                os.environ['KERASTUNER_ORACLE_IP'] = '127.0.0.1'
                os.environ['KERASTUNER_ORACLE_PORT'] = port
                # Workers that are part of the same multi-worker
                # DistributionStrategy should have the same TUNER_ID.
                os.environ['KERASTUNER_TUNER_ID'] = 'worker{}'.format(i)
                fn()
            worker_thread = ExceptionStoringThread(target=worker_fn)
            worker_thread.start()
            worker_threads.append(worker_thread)

        for worker_thread in worker_threads:
            worker_thread.join()

        if chief_thread.raised_exception:
            six.reraise(*chief_thread.raised_exception)
        for worker_thread in worker_threads:
            if worker_thread.raised_exception is not None:
                six.reraise(*worker_thread.raised_exception) 
开发者ID:keras-team,项目名称:keras-tuner,代码行数:43,代码来源:mock_distribute.py


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