def test_outOfMemory(self): def handleException(ex): self.assertTrue(isinstance(ex, Exception)) self.setTestValue(3) # temporarily redirect stderr to devnull to supress tcmalloc output # without this, tcmalloc prints out an error message when we try to allocate # too big a block. # # we need to use low level file descriptor trickery because # the code that writes to stderr is not python code but C code. sys.stderr.flush() newstderr = os.dup(sys.stderr.fileno()) devnull = open(os.devnull, 'w') os.dup2(devnull.fileno(), sys.stderr.fileno()) devnull.close() thread = ManagedThread(target=self.allocateTooMuchMemory) thread.criticalErrorHandler = handleException thread.start() thread.join() # restore stderr to its original state os.dup2(newstderr, sys.stderr.fileno()) self.assertEqual(self.testValue, 3)
def test_thread_local_storage_dict(self): tester = TestPushable(2) with tester: thread = ManagedThread(target=self.stackCheckTest) thread.start() thread.join() if self.exception is not None: raise self.exception
def test_startWithArgument(self): thread = ManagedThread(target=self.setTestValue, args=(2,)) thread.start() thread.join() self.assertEqual(self.testValue, 2)
def test_startManagedThread(self): thread = ManagedThread(target=self.incrementTestValue) thread.start() thread.join() self.assertEqual(self.testValue, 1)
def test_startWithArgument(self): thread = ManagedThread(target=self.setTestValue, args=(2, )) thread.start() thread.join() self.assertEqual(self.testValue, 2)