def terminate()

in src/system/process.py [0:0]


    def terminate(self):
        if not self.started:
            raise ProcessNotStartedError()

        parent = psutil.Process(self.process.pid)
        logging.debug("Checking for child processes")
        child_processes = parent.children(recursive=True)
        for child in child_processes:
            logging.debug(f"Found child process with pid {child.pid}")
            if child.pid != self.process.pid:
                logging.debug(f"Sending SIGKILL to {child.pid} ")
                child.kill()
        logging.info(f"Sending SIGKILL to PID {self.process.pid}")

        self.process.kill()

        logging.info(f"Process killed with exit code {self.process.returncode}")

        if self.stdout:
            self.__stdout_data__ = self.stdout.read()
            self.stdout.close()
            self.stdout = None

        if self.stderr:
            self.__stderr_data__ = self.stderr.read()
            self.stderr.close()
            self.stderr = None

        self.return_code = self.process.returncode
        self.process = None

        return self.return_code