From fe30d4fdf6a97cf6fa8bc73baac24cc4d815f4f6 Mon Sep 17 00:00:00 2001 From: Tim Ryan Date: Wed, 29 Jul 2015 10:54:50 -0700 Subject: [PATCH] Removes observers when API thread terminates. --- droneapi/lib/__init__.py | 10 ++++++++++ droneapi/module/api.py | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/droneapi/lib/__init__.py b/droneapi/lib/__init__.py index b7074ef6b..cc671db4e 100644 --- a/droneapi/lib/__init__.py +++ b/droneapi/lib/__init__.py @@ -395,6 +395,16 @@ def notify_observers(self, attr_name): except Exception as e: print("Error calling observer: ", e) + def remove_all_observers(self): + """ + Internal function. Do not use. + + This method removes all attached observers. + + .. INTERNAL NOTE: (For subclass use only) + """ + self.__observers = {} + class Vehicle(HasObservers): """ The main vehicle API diff --git a/droneapi/module/api.py b/droneapi/module/api.py index 0992a1e7a..18ef09beb 100644 --- a/droneapi/module/api.py +++ b/droneapi/module/api.py @@ -341,6 +341,11 @@ def run(self): self.module.mpstate.rx_blacklist.remove('STATUSTEXT') except: pass # Silently work with old mavproxies + + # Remove all observers. + self.module.vehicle.remove_all_observers() + self.module.vehicle.unset_mavlink_callback() + self.module.thread_remove(self) def __str__(self):