class_docstr: A controller/agent that populates a Launch RunQueue from a hyperparameter sweep.
class_docstr_tok: ["A","controller\/agent","that","populates","a","Launch","RunQueue","from","a","hyperparameter","sweep","."]
docstr: Use the public api to get state of a run.
docstr_tok: ["Use","the","public","api","to","get","state","of","a","run","."]
code: def _get_run_state(
      self, run_id: str, prev_run_state: RunState = RunState.UNKNOWN
  ) -> RunState:
      """Use the public api to get state of a run."""
      run_state = None
      try:
          state = self._api.get_run_state(
              self._entity, self._project, run_id
          )
          run_state = RunState(state)
      except CommError as e:
          _logger.debug(f"error getting state for run ({run_id}): {e}")
          if prev_run_state == RunState.UNKNOWN:
              # triggers when we get an unknown state for the second time
              wandb.termwarn(
                  f"Failed to get runstate for run ({run_id}). Error: {traceback.format_exc()}"
              )
              run_state = RunState.FAILED
          else:  # first time we get unknwon state
              run_state = RunState.UNKNOWN
      except (AttributeError, ValueError):
          wandb.termwarn(
              f"Bad state ({run_state}) for run ({run_id}). Error: {traceback.format_exc()}"
          )
          run_state = RunState.UNKNOWN
      return run_state
  
imports: import asyncio
  import base64
  import logging
  import os
  import socket
  import threading
  import time
  import traceback
  from abc import ABC, abstractmethod
  from dataclasses import dataclass
  from enum import Enum
  from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Tuple, Union
  import click
  import yaml
  import wandb
  from wandb.errors import CommError
  from wandb.sdk.launch._launch_add import launch_add
  from wandb.sdk.launch.errors import LaunchError
  from wandb.sdk.launch.sweeps import SchedulerError
  from wandb.sdk.launch.sweeps.utils import create_sweep_command_args, make_launch_sweep_entrypoint
  from wandb.sdk.launch.utils import event_loop_thread_exec
  from wandb.sdk.lib.runid import generate_id
label_desc: Use image node_id 30 for calling the Scheduler obj's underlying member method code with example usage: obj._get_run_state(run_id, prev_run_state) and returns: run_state