How to use the portpicker.pick_unused_port function in portpicker

To help you get started, we’ve selected a few portpicker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / grr / grr / server / grr_response_server / gui / gui_test_lib.py View on Github external
def setUpClass(cls):
    super(GRRSeleniumTest, cls).setUpClass()
    with GRRSeleniumTest._selenium_set_up_lock:
      if not GRRSeleniumTest._selenium_set_up_done:

        port = portpicker.pick_unused_port()
        logging.info("Picked free AdminUI port %d.", port)

        # Start up a server in another thread
        GRRSeleniumTest._server_trd = wsgiapp_testlib.ServerThread(
            port, name="SeleniumServerThread")
        GRRSeleniumTest._server_trd.StartAndWaitUntilServing()
        GRRSeleniumTest._SetUpSelenium(port)

        GRRSeleniumTest._selenium_set_up_done = True
github qing8137 / StarCraft2-Happy-Kitting / DQN / pysc2 / bin / play_vs_agent.py View on Github external
def host():
  """Run a host which expects one player to connect remotely."""
  run_config = run_configs.get()

  map_inst = maps.get(FLAGS.map)

  if not FLAGS.rgb_screen_size or not FLAGS.rgb_minimap_size:
    logging.info("Use --rgb_screen_size and --rgb_minimap_size if you want rgb "
                 "observations.")

  while True:
    start_port = portpicker.pick_unused_port()
    ports = [start_port + p for p in range(4)]  # 2 * num_players
    if all(portpicker.is_port_free(p) for p in ports):
      break

  host_proc = run_config.start(extra_ports=ports, host=FLAGS.host,
                               timeout_seconds=300, window_loc=(50, 50))
  client_proc = run_config.start(extra_ports=ports, host=FLAGS.host,
                                 connect=False, window_loc=(700, 50))

  create = sc_pb.RequestCreateGame(
      realtime=FLAGS.realtime, local_map=sc_pb.LocalMap(map_path=map_inst.path))
  create.player_setup.add(type=sc_pb.Participant)
  create.player_setup.add(type=sc_pb.Participant)

  controller = host_proc.controller
  controller.save_map(map_inst.path, map_inst.data(run_config))
github diux-dev / cluster / launch_async_adder.py View on Github external
def __init__(self, job, task_id):
    self.job = job
    self.ip = '127.0.0.1' # hostname/ip address
    self.id = task_id
    self.port = portpicker.pick_unused_port()
github diux-dev / cluster / benchmark_grpc_recv.py View on Github external
def run_benchmark_distributed():
  ops = create_graph("/job:worker/task:0", "/job:worker/task:1")
  queues = [create_done_queue(0), create_done_queue(1)]

  # launch distributed service


  port0, port1 = [portpicker.pick_unused_port() for _ in range(2)]
  flags = " ".join(sys.argv)  # pass parent flags to children
  
  def run_worker(w):
    my_env = os.environ.copy()
    if not FLAGS.verbose:
      my_env["CUDA_VISIBLE_DEVICES"] = ""
      my_env["TF_CPP_MIN_LOG_LEVEL"] = "2"
    if FLAGS.profile:
      my_env["LD_PRELOAD"]="/usr/lib/libtcmalloc_and_profiler.so.4"
      my_env["CPUPROFILE"]="/tmp/profile.out.%s"%(w)
    cmd = "python %s --task=%d --port0=%s --port1=%s"%(flags, w, port0, port1)
    subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT,
                     env=my_env)
    
  run_worker(0)
  run_worker(1)
github Khan / frankenserver / python / google / appengine / tools / devappserver2 / api_server.py View on Github external
options.running_datastore_emulator_host)
    env_emulator_host = os.environ.get('DATASTORE_EMULATOR_HOST')
    if env_emulator_host:  # emulator already running, reuse it.
      logging.warning(
          'Detected environment variable DATASTORE_EMULATOR_HOST=%s, '
          'dev_appserver will speak to the Cloud Datastore emulator running on '
          'this address. The datastore_path %s will be neglected.\nIf you '
          'want datastore to store on %s, remove DATASTORE_EMULATOR_HOST '
          'from environment variables and restart dev_appserver',
          env_emulator_host, datastore_path, datastore_path)
    else:
      gcd_emulator_launching_thread = _launch_gcd_emulator(
          app_id=app_id,
          emulator_port=(options.datastore_emulator_port
                         if options.datastore_emulator_port else
                         portpicker.pick_unused_port()),
          silent=options.dev_appserver_log_level != 'debug',
          index_file=os.path.join(app_root, 'index.yaml'),
          require_indexes=options.require_indexes,
          datastore_path=datastore_path,
          stub_type=stub_type,
          cmd=options.datastore_emulator_cmd,
          is_test=options.datastore_emulator_is_test_mode,
          auto_id_policy=options.auto_id_policy)
  else:
    # Use SQLite stub.
    # For historic reason we are still supporting conversion from file stub to
    # SQLite stub data. But this conversion will go away.



    if stub_type == datastore_converter.StubTypes.PYTHON_FILE_STUB:
github Dentosal / python-sc2 / sc2 / portconfig.py View on Github external
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)]
github Dentosal / python-sc2 / sc2 / sc2process.py View on Github external
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
github google / grr / grr / server / grr_response_server / gui / api_regression_http.py View on Github external
  @staticmethod
  def GetConnector(api_version):
    if api_version not in [1, 2]:
      raise ValueError("api_version may be 1 or 2 only")

    with _HTTP_ENDPOINTS_LOCK:
      if api_version not in _HTTP_ENDPOINTS:
        port = portpicker.pick_unused_port()
        logging.info("Picked free AdminUI port %d.", port)

        # Force creation of new APIAuthorizationManager.
        api_auth_manager.InitializeApiAuthManager()

        trd = wsgiapp_testlib.ServerThread(
            port, name="ApiRegressionHttpConnectorV%d" % api_version)
        trd.StartAndWaitUntilServing()

        _HTTP_ENDPOINTS[api_version] = "http://localhost:%d" % port

      return http_connector.HttpConnector(
          api_endpoint=_HTTP_ENDPOINTS[api_version])

portpicker

A library to choose unique available network ports.

Apache-2.0
Latest version published 1 year ago

Package Health Score

73 / 100
Full package analysis