code: def _get_num_threads(pid):
      """
      Function to get the number of threads a process is using
  
      Parameters
      ----------
      pid : integer
          the process ID of process to profile
  
      Returns
      -------
      num_threads : int
          the number of threads that the process is using
  
      """
  
      try:
          proc = psutil.Process(pid)
          # If process is running
          if proc.status() == psutil.STATUS_RUNNING:
              num_threads = proc.num_threads()
          elif proc.num_threads() > 1:
              tprocs = [
                  psutil.Process(thr.id) for thr in proc.threads()
              ]
              alive_tprocs = [
                  tproc
                  for tproc in tprocs
                  if tproc.status() == psutil.STATUS_RUNNING
              ]
              num_threads = len(alive_tprocs)
          else:
              num_threads = 1
  
          child_threads = 0
          # Iterate through child processes and get number of their threads
          for child in proc.children(recursive=True):
              # Leaf process
              if len(child.children()) == 0:
                  # If process is running, get its number of threads
                  if child.status() == psutil.STATUS_RUNNING:
                      child_thr = child.num_threads()
                  # If its not necessarily running, but still multi-threaded
                  elif child.num_threads() > 1:
                      # Cast each thread as a process and check for only running
                      tprocs = [
                          psutil.Process(thr.id)
                          for thr in child.threads()
                      ]
                      alive_tprocs = [
                          tproc
                          for tproc in tprocs
                          if tproc.status() == psutil.STATUS_RUNNING
                      ]
                      child_thr = len(alive_tprocs)
                  # Otherwise, no threads are running
                  else:
                      child_thr = 0
                  # Increment child threads
                  child_threads += child_thr
      except psutil.NoSuchProcess:
          return None
  
      # Number of threads is max between found active children and parent
      num_threads = max(child_threads, num_threads)
  
      # Return number of threads found
      return num_threads
  
imports: import os
  import numpy
  import threading
  from time import time
  from ..None import config, logging
label_desc: Use image node_id 4 for calling a global function with example usage: _get_num_threads(pid) and returns: num_threads, None