code: def terminate(self, signal_chain=KILL_CHAIN, kill_wait=KILL_WAIT_SEC, purge=True):
      
      alive = self.is_alive()
      if alive:
        logger.debug('terminating {}'.format(self._name))
        for signal_type in signal_chain:
          pid = self.pid
          try:
            logger.debug('sending signal {} to pid {}'.format(signal_type, pid))
            self._kill(signal_type)
          except OSError as e:
            logger.warning('caught OSError({e!s}) during attempt to kill -{signal} {pid}!'
                           .format(e=e, signal=signal_type, pid=pid))
  
          # Wait up to kill_wait seconds to terminate or move onto the next signal.
          try:
            if self._deadline_until(self.is_dead, 'daemon to exit', timeout=kill_wait):
              alive = False
              logger.debug('successfully terminated pid {}'.format(pid))
              break
          except self.Timeout:
            # Loop to the next kill signal on timeout.
            pass
  
      if alive:
        raise ProcessManager.NonResponsiveProcess('failed to kill pid {pid} with signals {chain}'
                                        .format(pid=self.pid, chain=signal_chain))
  
      if purge:
        self.purge_metadata(force=True)
docs: Ensure a process is terminated by sending a chain of kill signals (SIGTERM, SIGKILL).