aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTat-Chee Wan (USM)2011-05-19 09:15:52 +0800
committerTat-Chee Wan (USM)2011-05-19 09:15:52 +0800
commit4e4321aac2ac5c1ddc7c26736480ff2358827288 (patch)
tree7dfb432d281723155f673b51a095d7b8c50222da
parent6a255ea54d7391a955bd0aff5089b0502fa9b639 (diff)
added checks to del pool to make it safer
Closing a NXT object sometimes trigger the following error *** attempt to pop an unknown autorelease pool Added checks to make deleting NSAutoreleasePool safer
-rw-r--r--pyfantom.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/pyfantom.py b/pyfantom.py
index a5e4419..02a36e8 100644
--- a/pyfantom.py
+++ b/pyfantom.py
@@ -224,8 +224,10 @@ class NXTIterator:
Status.check(status)
if self.pool is not None:
del self.pool
+ self.pool = None
if self.nsapp is not None:
del self.nsapp
+ self.nsapp = None
if self.debug:
print "pyfantom: NXTIterator destroyed."
self.__destroy = destroy
@@ -296,6 +298,7 @@ class NXT:
self.debug = DEBUG
self.handle = None
self.isBTLink = bluetooth # Not used for now
+ self.pool = None
if isinstance(name_or_handle, basestring):
status = StatusVar(0)
handle = dll.nFANTOM100_createNXT(name_or_handle, cast(byref(status), POINTER(c_int)),
@@ -304,9 +307,10 @@ class NXT:
self.handle = handle
else:
self.handle = name_or_handle
- # Initialize self.pool here to avoid dll.nFANTOM100_createNXT() triggering
- # an autorelease pool error message if it failed
- self.pool = NSAutoreleasePool.alloc().init()
+ if platform.system() == 'Darwin':
+ # Initialize self.pool here to avoid dll.nFANTOM100_createNXT() triggering
+ # an autorelease pool error message if it failed
+ self.pool = NSAutoreleasePool.alloc().init()
def destroy():
"""To be used in destructor."""
if self.debug:
@@ -315,9 +319,12 @@ class NXT:
status = StatusVar(0)
dll.nFANTOM100_destroyNXT(self.handle, cast(byref(status), POINTER(c_int)))
Status.check(status)
- del self.pool
+ self.handle = None
if self.debug:
print "pyfantom: NXT destroyed."
+ if self.pool is not None:
+ del self.pool
+ self.pool = None
else:
if self.debug:
print "pyfantom: NXT handle is None!"
@@ -431,7 +438,6 @@ class NXT:
print "pyfantom: close()"
if self.handle is not None:
self.__destroy()
- self.handle = None
else:
if self.debug:
print "pyfantom: No NXT in close()."