aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas Schodet2011-03-30 20:58:22 +0200
committerNicolas Schodet2011-03-30 21:02:02 +0200
commita14e5945cd8b833d889a440c513adc878bf82e6b (patch)
treecebc73632196f792d3d31a4676b0bd87041faa3c
parentcbd7315e3adc1f8752ec09341e61d15a790e84f5 (diff)
solve destructor race condition
-rw-r--r--pyfantom.py16
1 files 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