Skip to content

Commit

Permalink
mavcan: ensure child dies when parent dies
Browse files Browse the repository at this point in the history
this prevents stale mavcan drivers from sending MAVLink packets
  • Loading branch information
tridge committed Aug 5, 2024
1 parent 8dd60c5 commit b76d480
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions dronecan/driver/mavcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit b76d480

Please sign in to comment.