class_docstr: See documentation here
  
  https://wiki.yandex-team.ru/yatool/test/#python-acquire-ports
class_docstr_tok: ["See","documentation","here","https",":","\/\/wiki.yandex-team.ru\/yatool\/test\/","#","python-acquire-ports"]
code: def get_port_range(self, start_port, count, random_start=True):
      assert count > 0
      if start_port and self._no_random_ports():
          return start_port
  
      candidates = []
  
      def drop_candidates():
          for port in candidates:
              self._release_port_no_lock(port)
          candidates[:] = []
  
      with self._lock:
          for attempts in six.moves.range(128):
              for left, right in self._valid_range:
                  if right - left < count:
                      continue
  
                  if random_start:
                      start = random.randint(
                          left, right - ((right - left) // 2)
                      )
                  else:
                      start = left
                  for probe_port in six.moves.range(start, right):
                      if self._capture_port_no_lock(
                          probe_port, socket.SOCK_STREAM
                      ):
                          candidates.append(probe_port)
                      else:
                          drop_candidates()
  
                      if len(candidates) == count:
                          return candidates[0]
                  # Can't find required number of ports without gap in the current range
                  drop_candidates()
  
          raise PortManagerException(
              "Failed to find valid port range (start_port: {} count: {}) (range: {} used: {})".format(
                  start_port, count, self._valid_range, self._filelocks
              )
          )
  
imports: import os
  import errno
  import socket
  import random
  import logging
  import platform
  import threading
  import six
label_desc: Use image node_id 11 for calling the PortManager obj's underlying member method code with example usage: obj.get_port_range(start_port, count, random_start) and returns: start_port, candidates