code: def test_ray_init_sigterm_handler():
      TEST_FILENAME = "sigterm.txt"
  
      def sigterm_handler_cmd(ray_init=False):
          return f"""
  import os
  import sys
  import signal
  def sigterm_handler(signum, frame):
      f = open("{TEST_FILENAME}", "w")
      sys.exit(0)
  signal.signal(signal.SIGTERM, sigterm_handler)
  
  import ray
  {"ray.init()" if ray_init else ""}
  os.kill(os.getpid(), signal.SIGTERM)
  """
  
      # test if sigterm handler is not overwritten by import ray
      test_child = subprocess.run(
          ["python", "-c", sigterm_handler_cmd()]
      )
      assert test_child.returncode == 0 and os.path.exists(
          TEST_FILENAME
      )
      os.remove(TEST_FILENAME)
  
      # test if sigterm handler is overwritten by ray.init
      test_child = subprocess.run(
          ["python", "-c", sigterm_handler_cmd(ray_init=True)]
      )
      assert (
          test_child.returncode == signal.SIGTERM
          and not os.path.exists(TEST_FILENAME)
      )
  
imports: import os
  import sys
  import unittest.mock
  import signal
  import subprocess
  import grpc
  import pytest
  import ray
  import ray._private.services
  from ray.client_builder import ClientContext
  from ray.cluster_utils import Cluster
  from ray.util.client.common import ClientObjectRef
  from ray.util.client.ray_client_helpers import ray_start_client_server
  from ray.util.client.worker import Worker
  from ray._private.test_utils import wait_for_condition, enable_external_redis
label_desc: Use image node_id 13 for calling a global function with example usage: test_ray_init_sigterm_handler() and returns: str, TEST_FILENAME, str, unknown, str