Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mavcan: ensure child dies when parent dies #67

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading