code: def forward_signals(
      p: subprocess.Popen,
      *signums: signal.Signals,
      signal_children: bool = False,
  ) -> Iterator[None]:
      """Forward a list of signals to a subprocess (and optionally all its children),
      restoring the original handlers afterwards.
  
      @param signal_children If true forward the signal to all the children as well.
      """
      if not signums:
          # Pick a useful default for wrapper processes.
          names = [
              "SIGINT",
              "SIGTERM",
              "SIGHUP",
              "SIGUSR1",
              "SIGUSR2",
              "SIGWINCH",
              "SIGBREAK",
          ]
          signums = tuple(
              getattr(signal, name)
              for name in names
              if hasattr(signal, name)
          )
  
      def signal_passthru(signum: Any, frame: Any) -> None:
          if signal_children:
              signal_process_tree(p, signum)
          p.send_signal(signum)
  
      old_handlers = [None for n in signums]  # type: List[Any]
      try:
          # Install passthru handlers.
          for i, n in enumerate(signums):
              old_handlers[i] = signal.signal(n, signal_passthru)
          yield
      finally:
          # restore original handlers
          for n, old in zip(signums, old_handlers):
              if old is None:
                  continue
              signal.signal(n, old)
  
imports: import collections
  import contextlib
  import copy
  import datetime
  import enum
  import errno
  import inspect
  import json
  import logging
  import math
  import numbers
  import os
  import pathlib
  import random
  import re
  import shutil
  import signal
  import socket
  import stat
  import subprocess
  import time
  import uuid
  from typing import Any, Callable, Dict, Iterator, List, Optional, Set, SupportsFloat, Tuple, Union, cast
  import psutil
  import determined
  from determined import constants
  from determined.common import check, detignore, util
label_desc: Use image node_id 22 for calling a global function with example usage: forward_signals(p) without return types