code: def test_sigterm_handler_can_be_added(tmpdir):
      handler_ran = False
  
      def handler(*_):
          nonlocal handler_ran
          handler_ran = True
  
      signal.signal(signal.SIGTERM, handler)
  
      class TestModel(BoringModel):
          def training_step(self, batch, batch_idx):
              os.kill(os.getpid(), signal.SIGTERM)
  
      model = TestModel()
      trainer = Trainer(
          default_root_dir=tmpdir,
          max_epochs=1,
          limit_train_batches=2,
          limit_val_batches=0,
      )
  
      assert not trainer.received_sigterm
      assert not handler_ran
      with pytest.raises(SIGTERMException):
          trainer.fit(model)
      assert trainer.received_sigterm
      assert handler_ran
  
      # reset the signal to system defaults
      signal.signal(signal.SIGTERM, signal.SIG_DFL)
  
imports: import concurrent.futures
  import os
  import signal
  from unittest import mock
  from unittest.mock import Mock
  import pytest
  from lightning.fabric.plugins.environments import SLURMEnvironment
  from lightning.fabric.utilities.imports import _IS_WINDOWS
  from lightning.pytorch import Trainer
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.trainer.connectors.signal_connector import _SignalConnector
  from lightning.pytorch.utilities.exceptions import SIGTERMException
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 2 for calling a global function with example usage: test_sigterm_handler_can_be_added(tmpdir) without return types