diff --git a/route_guidance_ros/scripts/utilities.py b/route_guidance_ros/scripts/utilities.py index 8ff7edbd8686917b336cdb9dcef6de79c8e63e0f..0802b5e43b7db97165fbddff7ce1e4b35920e81b 100644 --- a/route_guidance_ros/scripts/utilities.py +++ b/route_guidance_ros/scripts/utilities.py @@ -1,13 +1,22 @@ import time +import subprocess from subprocess import Popen +import atexit +def register_process_killer(process): + def kill_subprocess(pid): + subprocess.run(["kill", "-SIGKILL", str(pid)]) + print("process {} was killed.".format(pid)) + atexit.register(kill_subprocess, process.pid) class SubprocessWrapper(object): def __init__(self, command): self.process = Popen(command) + register_process_killer(self.process) - def __del__(self): - self.process.kill() + # It is not guaranteed that __del__() methods are called when the interpreter exits. + # def __del__(self): + # self.process.kill() class ComponentWrapper(SubprocessWrapper):