code: def test_defer_sigint():
      # Tests a helper context manager for deferring SIGINT signals until after the
      # context is left. This is used by Ray's task cancellation to defer cancellation
      # interrupts during problematic areas, e.g. task argument deserialization.
      signal_was_deferred = False
      orig_sigint_handler = signal.getsignal(signal.SIGINT)
      try:
          with 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
      except KeyboardInterrupt:
          # Check that SIGINT was deferred until the end of the context.
          assert signal_was_deferred
          # Check that original SIGINT handler was restored.
          assert signal.getsignal(signal.SIGINT) is orig_sigint_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 4 for calling a global function with example usage: test_defer_sigint() without return types