code: def _kill_process_if_needed(
      process: subprocess.Popen,
      timeout_s: float = 10,
      poll_interval_s: float = 1.0,
  ):
      """Kills a process if it hasn't finished in `timeout_s` seconds.
      Polls every `poll_interval_s` seconds to check if the process is still running.
      """
      kill_timeout = time.monotonic() + timeout_s
      while process.poll() is None and time.monotonic() < kill_timeout:
          time.sleep(poll_interval_s)
      if process.poll() is None:
          process.terminate()
  
file_path: ray/python/ray/air/tests/test_experiment_restore.py
imports: import json
  import os
  import numpy
  import pandas
  from pathlib import Path
  import pytest
  import time
  import shutil
  import signal
  import subprocess
  import sys
  from ray.tune.result_grid import ResultGrid
  from ray.tune.analysis import ExperimentAnalysis
label_desc: Use image node_id 1 for calling a global function with example usage: _kill_process_if_needed(process, timeout_s, poll_interval_s) without return types