class_docstr: UnmanagedTrialHeartbeat updates the state on context enter/exit.
code: def _exit_handler(self) -> None:
      # TODO(ilia): check if we need to explicitly log the exception, e.g. if it was not
      # intercepted by the stdout/stderr capture.
      if self._hook.exception:
          exc = self._hook.exception
          self.close(type(exc), exc, None)
      elif (
          self._hook.exit_code is not None and self._hook.exit_code != 0
      ):
          exc = RuntimeError(f"exit code {self._hook.exit_code}")
          self.close(type(exc), exc, None)
      else:
          self.close()
  
imports: import atexit
  import logging
  import sys
  import threading
  import time
  import types
  from typing import Any, Optional, Union
  from determined.common import api
  from determined.common.api import bindings
label_desc: Use image node_id 3 for calling the _UnmanagedTrialHeartbeat obj's underlying member method code with example usage: obj._exit_handler() without return types