Select remaining containers that didn't have priorities to start
183116
def _start_remaining_containers(self, containers_remaining, tool_d):
        
        s_containers = []
        f_containers = []
        for container in containers_remaining:
            s_containers, f_containers = self._start_container(container,
                                                               tool_d,
                                                               s_containers,
                                                               f_containers)
        return (s_containers, f_containers)
1296867
def start_numbered_list(self):
        """"""
        self._ordered = True
        self.start_container(List, stylename='_numbered_list')
        self.set_next_paragraph_style('numbered-list-paragraph'
                                      if self._item_level <= 0
                                      else 'sublist-paragraph')
1040711
protected void repairAfterLazy() {
    for (int k = 0; k < highLowContainer.size(); ++k) {
      MappeableContainer c = highLowContainer.getContainerAtIndex(k);
      ((MutableRoaringArray) highLowContainer).setContainerAtIndex(k, c.repairAfterLazy());
    }
  }
514299
async def _init_clean(self):
        
        # Data about running containers
        self._containers_running = {}
        self._container_for_job = {}

        self._student_containers_running = {}
        self._student_containers_for_job = {}

        self._containers_killed = dict()

        # Delete tmp_dir, and recreate-it again
        try:
            await self._ashutil.rmtree(self._tmp_dir)
        except OSError:
            pass

        try:
            await self._aos.mkdir(self._tmp_dir)
        except OSError:
            pass

        # Docker
        self._docker = AsyncProxy(DockerInterface())

        # Auto discover containers
        self._logger.info("Discovering containers")
        self._containers = await self._docker.get_containers()

        self._assigned_external_ports = {}  # container_id : [external_ports]

        if self._address_host is None and len(self._containers) != 0:
            self._logger.info("Guessing external host IP")
            self._address_host = await self._docker.get_host_ip(next(iter(self._containers.values()))["id"])
        if self._address_host is None:
            self._logger.warning(
                "Cannot find external host IP. Please indicate it in the configuration. Remote SSH debug has been deactivated.")
            self._external_ports = None
        else:
            self._logger.info("External address for SSH remote debug is %s", self._address_host)

        # Watchers
        self._timeout_watcher = TimeoutWatcher(self._docker)
28797
async def clean(self):
        
        for x in self._running_asyncio_tasks:
            x.cancel()
        self._container_had_error = set()
        self._watching = set()
        self._running_asyncio_tasks = set()
503843
def prioSort(elements):
    """"""
    # Randomize the services before sorting so that equal priority
    # elements are load-balanced.
    random.shuffle(elements)

    prio_elems = [(getPriority(e), e) for e in elements]
    prio_elems.sort()
    sorted_elems = [s for (_, s) in prio_elems]
    return sorted_elems
1119279
def skip(self, count):
        '''
        
        '''
        self._initialize()
        skipped = 0
        if not self._exhausted():
            skipped = min(count, self._last_index() - self._current_index)
            self._current_index += skipped
        return skipped
581255
def _harvest_lost_resources(self):
        """"""
        with self._lock:
            for i in self._unavailable_range():
                rtracker = self._reference_queue[i]
                if rtracker is not None and rtracker.available():
                    self.put_resource(rtracker.resource)
1064627
def containers_running(get_container_name):
    
    running = []
    for n in ['web', 'postgres', 'solr', 'datapusher', 'redis']:
        info = docker.inspect_container(get_container_name(n))
        if info and not info['State']['Running']:
            running.append(n + '(halted)')
        elif info:
            running.append(n)
    return running
335926
def _skip(options):
    """"""
    values = [options.missing_direct_deps, options.unnecessary_deps]
    return all(v == 'off' for v in values)
238746
def stop_containers(self):
        
        while len(self._containers):
            container = self._containers.pop()
            try:
                container.kill(signal.SIGKILL)
            except docker.errors.APIError:  # probably doesn't exist anymore
                pass
408593
private CompletableFuture<Void> stopContainer(int containerId) {
        log.info("Stopping Container {}.", containerId);
        ContainerHandle handle = handles.get(containerId);
        if (handle == null) {
            log.warn("Container {} handle is null, container is pending start or already unregistered.", containerId);
            return null;
        } else {
            this.pendingTasks.add(containerId);
            try {
                return registry
                        .stopContainer(handle, CLOSE_TIMEOUT_PER_CONTAINER)
                        .whenComplete((aVoid, throwable) -> {
                            if (throwable != null) {
                                log.warn("Stopping container {} failed: {}", containerId, throwable);
                            }
                            try {
                                // We remove the handle and don't attempt retry on stop container failures.
                                unregisterHandle(containerId);
                            } finally {
                                // The pending task has to be removed after the handle is removed to avoid inconsistencies
                                // with the container state.
                                // Using finally block to ensure this is always called, otherwise this will prevent other
                                // tasks from being attempted for this container id.
                                this.pendingTasks.remove(containerId);
                            }
                        });
            } catch (Throwable e) {
                // The pending task has to be removed on all failures to enable retries.
                this.pendingTasks.remove(containerId);
                throw e;
            }
        }
    }
145237
private static Collection<Container> keepOnlyLastIndexedContainer(Collection<Container> existingContainers, final String partiallyApplied) {

        Collection<Container> result = new ArrayList<>(existingContainers);

        // No index place holder, so nothing to filters
        if (!partiallyApplied.contains(INDEX_PLACEHOLDER)) {
            return result;
        }

        Map<String,Container> containerMap = existingContainers.stream().collect(Collectors.toMap(Container::getName, Function.identity()));

        Container last = null;
        for (long i = 1; i < Long.MAX_VALUE; i++) {
            final String withIndexApplied = partiallyApplied.replaceAll(INDEX_PLACEHOLDER, String.valueOf(i));
            Container mapped = containerMap.get(withIndexApplied);
            if (mapped != null) {
                result.remove(mapped);
                last = mapped;
            } else {
                // Readd last one removed (if any)
                if (last != null) {
                    result.add(last);
                }
                return result;
            }
        }
        throw new IllegalStateException("Internal error: Cannot find a free container index slot in " + existingContainers);
    }
898225
@VisibleForTesting
  void tryCleanupPods() {
    var pods = client.pods().list().getItems();
    pods.stream()
        .map(pod -> runAsync(guard(() -> tryCleanupPod(pod)), executor))
        .collect(toList())
        .forEach(CompletableFuture::join);
    tracer.getCurrentSpan().addAnnotation("processed",
        Map.of("pods", AttributeValue.longAttributeValue(pods.size())));

  }
1025808
def _get_containers(self):
        """"""
        buckets = self.native_conn.get_all_buckets()
        return [self.cont_cls.from_bucket(self, b) for b in buckets]
1306978
def cleanup():
    """"""
    lib_dir = os.path.join(os.environ['CONTAINER_DIR'], '_lib')
    if os.path.exists(lib_dir):
        shutil.rmtree(lib_dir)
    os.mkdir(lib_dir)
155322
function(opts) {

    // Start flag collector
    var flags = [];

    // Return empty if we have no opts
    if (!opts) {
      return flags;
    }

    // Inspect opts
    if (opts.q) {
      flags.push('-q');
    }

    // Daemon opts
    if (opts.background) {
      flags.push('-d');
    }

    // Recreate opts
    if (opts.recreate) {
      flags.push('--force-recreate');
    }

    // Removal opts
    if (opts.force) {
      flags.push('--force');
    }
    if (opts.volumes) {
      flags.push('-v');
    }

    // Run options
    // Do not start linked containers
    if (opts.noDeps) {
      flags.push('--no-deps');
    }
    // Change the entrypoint
    if (opts.entrypoint) {
      flags.push('--entrypoint');
      if (_.isArray(opts.entrypoint)) {
        flags.push(kbox.util.shell.escSpaces(opts.entrypoint.join(' ')));
      }
      else {
        flags.push(opts.entrypoint);
      }
    }
    // Remove the container after the run is done
    if (opts.rm) {
      flags.push('--rm');
    }
    // Add additional ENVs
    if (opts.environment) {
      _.forEach(opts.environment, function(envVar) {
        flags.push('-e');
        flags.push(envVar);
      });
    }

    // Return any and all flags
    return flags;

  }