code: def test_defer_sigint_noop_in_non_main_thread():
      # Tests that we don't try to defer SIGINT when not in the main thread.
  
      # Check that DeferSigint.create_if_main_thread() does not return DeferSigint when
      # not in the main thread.
      def check_no_defer():
          cm = DeferSigint.create_if_main_thread()
          assert not isinstance(cm, DeferSigint)
  
      check_no_defer_thread = threading.Thread(target=check_no_defer)
      try:
          check_no_defer_thread.start()
          check_no_defer_thread.join()
      except AssertionError as e:
          pytest.fail(
              "DeferSigint.create_if_main_thread() unexpected returned a DeferSigint "
              f"instance when not in the main thread: {e}"
          )
  
      # Check that signal is not deferred when trying to defer it in not the main thread.
      signal_was_deferred = False
  
      def maybe_defer():
          nonlocal signal_was_deferred
  
          with DeferSigint.create_if_main_thread() as cm:
              # Check that DeferSigint context manager was NOT returned.
              assert not isinstance(cm, DeferSigint)
              # Send singal to current process.
              # NOTE: We use _thread.interrupt_main() instead of os.kill() in order to
              # support Windows.
              _thread.interrupt_main()
              # Wait for signal to be delivered.
              time.sleep(1)
              # Signal should have been delivered by here, so we consider it deferred if
              # this is reached.
              signal_was_deferred = True
  
      # Create thread that will maybe defer SIGINT.
      maybe_defer_thread = threading.Thread(target=maybe_defer)
      try:
          maybe_defer_thread.start()
          maybe_defer_thread.join()
          # KeyboardInterrupt should get raised in main thread.
      except KeyboardInterrupt:
          # Check that SIGINT was not deferred.
          assert not signal_was_deferred
          # Check that original SIGINT handler was not overridden.
          assert (
              signal.getsignal(signal.SIGINT)
              is signal.default_int_handler
          )
      else:
          pytest.fail("SIGINT signal was never sent in test")
  
imports: import os
  import random
  import signal
  import sys
  import threading
  import _thread
  import time
  import pytest
  import ray
  from ray.exceptions import TaskCancelledError, RayTaskError, GetTimeoutError, WorkerCrashedError, ObjectLostError
  from ray._private.utils import DeferSigint
  from ray._private.test_utils import SignalActor, wait_for_condition
  from ray.util.state import list_tasks
label_desc: Use image node_id 6 for calling a global function with example usage: test_defer_sigint_noop_in_non_main_thread() without return types