Example #1
0
 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
Example #2
0
    def test_daemonByDefault(self):
        def doNothing():
            pass

        thread = ManagedThread(target=doNothing)

        self.assertTrue(thread.daemon)
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
 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
Example #6
0
    def test_startWithArgument(self):
        thread = ManagedThread(target=self.setTestValue, args=(2,))
        thread.start()
        thread.join()

        self.assertEqual(self.testValue, 2)
Example #7
0
    def test_startManagedThread(self):
        thread = ManagedThread(target=self.incrementTestValue)
        thread.start()
        thread.join()

        self.assertEqual(self.testValue, 1)
Example #8
0
    def test_startWithArgument(self):
        thread = ManagedThread(target=self.setTestValue, args=(2, ))
        thread.start()
        thread.join()

        self.assertEqual(self.testValue, 2)
Example #9
0
    def test_startManagedThread(self):
        thread = ManagedThread(target=self.incrementTestValue)
        thread.start()
        thread.join()

        self.assertEqual(self.testValue, 1)
Example #10
0
    def test_createManagedThread(self):
        def doNothing():
            pass

        thread = ManagedThread(target=doNothing)