class_docstr: MockPreemptState uses threading to simulate the behavior of the long-
  polling requests call.
class_docstr_tok: ["MockPreemptState","uses","threading","to","simulate","the","behavior","of","the","long-","polling","requests","call","."]
docstr: session_get() is called from a background thread.
docstr_tok: ["session_get","(",")","is","called","from","a","background","thread","."]
code: def session_get(
      self, path: str, params: Dict[str, Any], timeout: float
  ) -> mock.MagicMock:
      """session_get() is called from a background thread."""
      # We only mock one GET endpoint.
      assert path.endswith("signals/preemption"), path
      assert "timeout_seconds" in params, params
  
      timeout_seconds = float(params["timeout_seconds"])
      deadline = time.time() + timeout_seconds
  
      def wait_for_preemption() -> None:
          if timeout_seconds == 0:
              return
          with self._cond:
              while self._state is False:
                  now = time.time()
                  if now >= deadline:
                      return
                  try:
                      self._cond.wait(timeout=deadline - now)
                  except TimeoutError:
                      return
  
      # Wait for the preemption signal or until the deadline is reached.
      wait_for_preemption()
  
      response = mock.MagicMock()
      response.json.return_value = {"preempt": self._state}
      return response
  
file_path: determined/harness/tests/core/test_preempt.py
imports: import threading
  import time
  from typing import Any, Dict, Tuple
  from unittest import mock
  import pytest
  from determined import core
  from tests import parallel
label_desc: Use image node_id 3 for calling the MockPreemptState obj's underlying member method code with example usage: obj.session_get(path, params, timeout) and returns: response