From 4e4321aac2ac5c1ddc7c26736480ff2358827288 Mon Sep 17 00:00:00 2001 From: Tat-Chee Wan (USM) Date: Thu, 19 May 2011 09:15:52 +0800 Subject: 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 --- pyfantom.py | 16 +++++++++++----- 1 file 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()." -- cgit v1.2.3