code: def manage_server_processes(
      processes: List[Tuple[str, Process]]
  ) -> None:
      if not processes:
          return
  
      sigterm_called = [False]
  
      def _sigterm_handler(*_):
          sigterm_called[0] = True
  
      if sys.platform != "win32":
          signal.signal(signal.SIGTERM, _sigterm_handler)
  
      # Since frontends run user code, any of them could fail. In that case,
      # we want to fail all of them, as well as the application server, and
      # exit the command with an error status code.
  
      exitcode = 0
  
      while True:
          # We loop until
          # 1. Get a sigterm
          # 2. All the children died but all with exit code 0
          # 3. At-least one of the child died with non-zero exit code
  
          # sleeping quickly at the starting of every loop
          # moving this to the end of the loop might result in some flaky tests
          time.sleep(1)
  
          if sigterm_called[0]:
              print("Got SIGTERM. Exiting execution!!!")
              break
          if all(
              not p.is_alive() and p.exitcode == 0 for _, p in processes
          ):
              print(
                  "All the components are inactive with exitcode 0. Exiting execution!!!"
              )
              break
          if any(
              (not p.is_alive() and p.exitcode != 0)
              for _, p in processes
          ):
              print(
                  "Found dead components with non-zero exit codes, exiting execution!!! Components: "
              )
              print(
                  tabulate(
                      [
                          (name, p.exitcode)
                          for name, p in processes
                          if not p.is_alive() and p.exitcode != 0
                      ],
                      headers=["Name", "Exit Code"],
                  )
              )
              exitcode = 1
              break
  
      # sleeping for the last set of logs to reach stdout
      time.sleep(2)
  
      # Cleanup
      for _, p in processes:
          if p.is_alive():
              os.kill(p.pid, signal.SIGTERM)
  
      # Give processes time to terminate
      for _, p in processes:
          p.join(5)
  
      # clean the remaining ones.
      if any(p.is_alive() for _, p in processes):
          for _, p in processes:
              if p.is_alive():
                  os.kill(p.pid, signal.SIGKILL)
  
          # this sleep is just a precaution - signals might take a while to get raised.
          time.sleep(1)
          sys.exit(1)
  
      sys.exit(exitcode)
  
imports: import inspect
  import logging
  import os
  import signal
  import sys
  import time
  import traceback
  from functools import partial
  from multiprocessing import Process
  from typing import Callable, Dict, List, Optional, Tuple, TypedDict
label_desc: Use image node_id 8 for calling a global function with example usage: manage_server_processes(processes) without return types