From a14e5945cd8b833d889a440c513adc878bf82e6b Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 30 Mar 2011 20:58:22 +0200 Subject: solve destructor race condition --- pyfantom.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pyfantom.py b/pyfantom.py index 7d1f378..f5ddbb2 100644 --- a/pyfantom.py +++ b/pyfantom.py @@ -174,6 +174,11 @@ class NXTIterator: self.bluetooth_search_timeout_s = bluetooth_search_timeout_s self.handle = None self.stop = False + def destroy(): + """To be used in destructor.""" + status = c_int(0) + dll.nFANTOM100_destroyNXTIterator(self.handle, byref(status)) + self.__destroy = destroy def __iter__(self): """Return the iterator object itself.""" @@ -225,8 +230,7 @@ class NXTIterator: def __del__(self): """Destroy iterator.""" if self.handle is not None: - status = c_int(0) - dll.nFANTOM100_destroyNXTIterator(self.handle, byref(status)) + self.__destroy() class NXT: """Interface to the NXT brick.""" @@ -244,6 +248,11 @@ class NXT: self.handle = handle else: self.handle = name_or_handle + def destroy(): + """To be used in destructor.""" + status = c_int(0) + dll.nFANTOM100_destroyNXT(self.handle, byref(status)) + self.__destroy = destroy def get_firmware_version(self): """Get protocol and firmware versions installed on this NXT.""" @@ -309,8 +318,7 @@ class NXT: def __del__(self): """Destroy interface.""" if self.handle is not None: - status = c_int(0) - dll.nFANTOM100_destroyNXT(self.handle, byref(status)) + self.__destroy() if __name__ == '__main__': get_info = False -- cgit v1.2.3