code: 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
      )
  
imports: import time
  import portpicker
label_desc: Use image node_id 2 for calling a global function with example usage: pick_contiguous_unused_ports(num_ports, retry_interval_secs, retry_attempts) and returns: ports