From b76d4809a333e55f49267b409df164d9246f855d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 5 Aug 2024 20:36:16 +1000 Subject: [PATCH] mavcan: ensure child dies when parent dies this prevents stale mavcan drivers from sending MAVLink packets --- dronecan/driver/mavcan.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dronecan/driver/mavcan.py b/dronecan/driver/mavcan.py index 2631f45..094d754 100644 --- a/dronecan/driver/mavcan.py +++ b/dronecan/driver/mavcan.py @@ -34,7 +34,7 @@ def __init__(self, command, data): self.command = command self.data = data -def io_process(url, bus, target_system, baudrate, tx_queue, rx_queue, exit_queue): +def io_process(url, bus, target_system, baudrate, tx_queue, rx_queue, exit_queue, parent_pid): os.environ['MAVLINK20'] = '1' target_component = 0 @@ -121,6 +121,10 @@ def handle_control_message(m): if (not exit_queue.empty() and exit_queue.get() == "QUIT") or exit_proc: conn.close() return + if os.getppid() != parent_pid: + # ensure we die when parent dies + conn.close() + return while not tx_queue.empty(): if (not exit_queue.empty() and exit_queue.get() == "QUIT") or exit_proc: conn.close() @@ -200,7 +204,7 @@ def __init__(self, url, **kwargs): self.proc = multiprocessing.Process(target=io_process, name='mavcan_io_process', args=(url, self.bus, self.target_system, baudrate, - self.tx_queue, self.rx_queue, self.exit_queue)) + self.tx_queue, self.rx_queue, self.exit_queue, os.getpid())) self.proc.daemon = True self.proc.start()