class_docstr: Encapsulates running threads and processes of a Launchpad Program.
class_docstr_tok: ["Encapsulates","running","threads","and","processes","of","a","Launchpad","Program","."]
docstr: Waits for workers to finish. Also stops the program upon worker failures.
  
  Args:
    labels_to_wait_for: If supplied, only wait for these groups' workers to
      finish. Wait for all workers otherwise.
    raise_error: Raise an exception upon any worker failure.
    return_on_first_completed: Whether to return upon the first completed (or
      failed) worker.
  
  Raises:
    RuntimeError: if any worker raises an exception.
docstr_tok: ["Waits","for","workers","to","finish",".","Also","stops","the","program","upon","worker","failures",".","Args",":","labels_to_wait_for",":","If","supplied",",","only","wait","for","these","groups","'","workers","to","finish",".","Wait","for","all","workers","otherwise",".","raise_error",":","Raise","an","exception","upon","any","worker","failure",".","return_on_first_completed",":","Whether","to","return","upon","the","first","completed","(","or","failed",")","worker",".","Raises",":","RuntimeError",":","if","any","worker","raises","an","exception","."]
code: def wait(
      self,
      labels_to_wait_for: Optional[Sequence[Text]] = None,
      raise_error=True,
      return_on_first_completed=False,
  ):
      """Waits for workers to finish. Also stops the program upon worker failures.
  
      Args:
        labels_to_wait_for: If supplied, only wait for these groups' workers to
          finish. Wait for all workers otherwise.
        raise_error: Raise an exception upon any worker failure.
        return_on_first_completed: Whether to return upon the first completed (or
          failed) worker.
  
      Raises:
        RuntimeError: if any worker raises an exception.
      """
      active_workers = True
      while active_workers:
          with self._mutex:
              self._check_workers()
              active_workers = False
              if self._first_failure and raise_error:
                  failure = self._first_failure
                  self._first_failure = None
                  raise failure
              for label in (
                  labels_to_wait_for or self._active_workers.keys()
              ):
                  if self._active_workers[label]:
                      active_workers = True
                  if (
                      return_on_first_completed
                      and len(self._active_workers[label])
                      < self._workers_count[label]
                  ):
                      return
          time.sleep(0.1)
  
imports: import atexit
  import collections
  from concurrent import futures
  import os
  import signal
  import subprocess
  import sys
  import threading
  import time
  import traceback
  from typing import Optional, Sequence, Text
  from absl import flags
  from absl import logging
  from absl.testing import absltest
  from launchpad import flags
  import psutil
  import termcolor
label_desc: Use image node_id 18 for calling the WorkerManager obj's underlying member method code with example usage: obj.wait(labels_to_wait_for, raise_error, return_on_first_completed) without return types