code: def ensure_proc_terminate(proc):
      """
      Make sure processes terminate when main process exit.
  
      Args:
          proc (multiprocessing.Process or list)
      """
      if isinstance(proc, list):
          for p in proc:
              ensure_proc_terminate(p)
          return
  
      def stop_proc_by_weak_ref(ref):
          proc = ref()
          if proc is None:
              return
          if not proc.is_alive():
              return
          proc.terminate()
          proc.join()
  
      assert isinstance(proc, mp.Process)
      atexit.register(stop_proc_by_weak_ref, weakref.ref(proc))
  
imports: import sys
  import atexit
  import bisect
  import multiprocessing
  import platform
  import signal
  import threading
  import weakref
  from contextlib import contextmanager
  import six
  from six.moves import queue
  import subprocess
  from .None import logger
  from .argtools import log_once
label_desc: Use image node_id 1 for calling a global function with example usage: ensure_proc_terminate(proc) without return types