Skip to content
Snippets Groups Projects
Commit 7573ccc2 authored by Emil Harlan's avatar Emil Harlan
Browse files

a

parent 75997f0c
No related branches found
No related tags found
No related merge requests found
......@@ -9,21 +9,19 @@ class CommandExecutor(Node):
super().__init__('command_executor')
self.subscription = self.create_subscription(
String,
'execute_command',
'launch_node',
self.execute_command_callback,
10
)
self.running_processes = {} # Dictionary to store the running processes with custom names
def execute_command_callback(self, msg):
command = msg.data.split() # Split the received string into command and name
if command[0] == "kill":
self.kill_node(command[1]) # Call the kill_node method using 'self'
name, command = msg.data.split(" ", 1) # Split the received string into command and name
if command == "kill":
self.kill_node(command) # Call the kill_node method using 'self'
else:
name = command[0]
launch_command = " ".join(command[1:])
# Execute the launch command in a separate thread
threading.Thread(target=self.execute_command, args=(name, launch_command)).start()
threading.Thread(target=self.execute_command, args=(name, command)).start()
def execute_command(self, name, launch_command):
try:
......@@ -40,8 +38,8 @@ class CommandExecutor(Node):
if name in self.running_processes:
try:
process_handle = self.running_processes[name]
process_handle.terminate()
process_handle.wait(timeout=1)
process_handle.send_signal(SIGINT)
process_handle.wait(timeout=30)
except subprocess.TimeoutExpired:
process_handle.kill()
process_handle.wait()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment