diff --git a/python/GafferDispatch/LocalDispatcher.py b/python/GafferDispatch/LocalDispatcher.py index 62f01806978..4c1f03a2524 100644 --- a/python/GafferDispatch/LocalDispatcher.py +++ b/python/GafferDispatch/LocalDispatcher.py @@ -190,7 +190,7 @@ def messagesChangedSignal( self ) : def _execute( self ) : if self.__executeInBackground : - self.__backgroundTask = Gaffer.BackgroundTask( None, self.__executeInternal ) + self.__backgroundTask = Gaffer.BackgroundTask( None, Gaffer.WeakMethod( self.__executeInternal ) ) else : self.__executeInternal() diff --git a/python/GafferDispatchTest/LocalDispatcherTest.py b/python/GafferDispatchTest/LocalDispatcherTest.py index 1fe6e8a55b8..e47ce70c492 100644 --- a/python/GafferDispatchTest/LocalDispatcherTest.py +++ b/python/GafferDispatchTest/LocalDispatcherTest.py @@ -36,6 +36,7 @@ import datetime import errno +import gc import os import stat import shutil @@ -60,6 +61,16 @@ class LocalDispatcherTest( GafferTest.TestCase ) : + def tearDown( self ) : + + GafferTest.TestCase.tearDown( self ) + + # Check for Jobs existing past their expected lifetime (most likely through circular references). + self.assertEqual( + [ o for o in gc.get_objects() if isinstance( o, GafferDispatch.LocalDispatcher.Job ) ], + [] + ) + def __createLocalDispatcher( self, jobPool = None ) : if jobPool is None : @@ -528,7 +539,7 @@ def testFailure( self ) : self.assertFalse( os.path.isfile( s.context().substitute( s["n2"]["fileName"].getValue() ) ) ) self.assertFalse( os.path.isfile( s.context().substitute( s["n1"]["fileName"].getValue() ) ) ) - self.tearDown() + os.unlink( s.context().substitute( s["n3"]["fileName"].getValue() ) ) dispatcher["executeInBackground"].setValue( True ) dispatcher.dispatch( [ s["n1"] ] )