Ejemplo n.º 1
0
    def test_weakref_after_resurrection_threadsafe(self):
        gc.collect()

        prt = GCTestHelper.reflectionTraverseTestField()
        del prt
        self.assertEqual(gc.collect(), 1)

        prt = GCTestHelper.reflectionTraverseTestList()
        del prt
        self.assertEqual(gc.collect(), 1)

        prt = GCTestHelper.reflectionTraverseTestArray()
        del prt
        self.assertEqual(gc.collect(), 1)

        prt = GCTestHelper.reflectionTraverseTestPyList()
        del prt
        self.assertEqual(gc.collect(), 2)

        prt = GCTestHelper.reflectionTraverseTestCycle()
        del prt
        self.assertEqual(gc.collect(), 0)
Ejemplo n.º 2
0
    def test_TraverseByReflection(self):
        gc.collect()

        prt = GCTestHelper.reflectionTraverseTestField()
        del prt
        self.assertEqual(gc.collect(), 1)

        prt = GCTestHelper.reflectionTraverseTestList()
        del prt
        self.assertEqual(gc.collect(), 1)

        prt = GCTestHelper.reflectionTraverseTestArray()
        del prt
        self.assertEqual(gc.collect(), 1)

        prt = GCTestHelper.reflectionTraverseTestPyList()
        del prt
        self.assertEqual(gc.collect(), 2)

        prt = GCTestHelper.reflectionTraverseTestCycle()
        del prt
        self.assertEqual(gc.collect(), 0)
Ejemplo n.º 3
0
    def test_TraverseByReflection(self):
        gc.collect()

        prt = GCTestHelper.reflectionTraverseTestField()
        del prt
        self.assertEqual(gc.collect(), 1)

        prt = GCTestHelper.reflectionTraverseTestList()
        del prt
        self.assertEqual(gc.collect(), 1)

        prt = GCTestHelper.reflectionTraverseTestArray()
        del prt
        self.assertEqual(gc.collect(), 1)

        prt = GCTestHelper.reflectionTraverseTestPyList()
        del prt
        self.assertEqual(gc.collect(), 2)

        prt = GCTestHelper.reflectionTraverseTestCycle()
        del prt
        self.assertEqual(gc.collect(), 0)
Ejemplo n.º 4
0
    def test_forced_with_extern_NonPyObjectFinalizer_that_notifies_gc(self):
        comments = []

        class A:
            def __init__(self, index):
                self.index = index

            def __del__(self):
                comments.append("A_del_" + str(self.index))

        class PreProcess(Runnable):
            preCount = 0

            def run(self):
                PreProcess.preCount += 1

        class PostProcess(Runnable):
            postCount = 0

            def run(self):
                PostProcess.postCount += 1

        prePr = PreProcess()
        postPr = PostProcess()
        time.sleep(1)  #   <- to avoid that the newly registered processes
        #      become subject to previous run (remember: We
        #      are not in monitor-mode, i.e. gc runs async.
        gc.registerPreFinalizationProcess(prePr)
        gc.registerPostFinalizationProcess(postPr)
        for i in range(4):
            f = A(i)
            del f
        #NastyFinalizer would cause this test occasionally to fail
        externFinalizer = GCTestHelper.NotSoNastyFinalizer()
        del externFinalizer
        for i in range(4, 8):
            f = A(i)
            del f
        System.gc()
        # we wait a bit longer here, since PostProcess runs asynchronous
        # and must wait for the finalizer of A
        time.sleep(4)
        self.assertEqual(len(comments), 8)
        self.assertEqual(PreProcess.preCount, 1)
        self.assertEqual(PostProcess.postCount, 1)
        comments = []
        gc.unregisterPreFinalizationProcess(prePr)
        gc.unregisterPostFinalizationProcess(postPr)
Ejemplo n.º 5
0
 def test_Cycle(self):
     gc.collect()
     prt = GCTestHelper.reflectionTraverseTestCycle()
     del prt
     self.assertEqual(gc.collect(), 0)
Ejemplo n.º 6
0
 def test_PyList(self):
     gc.collect()
     prt = GCTestHelper.reflectionTraverseTestPyList()
     del prt
     self.assertEqual(gc.collect(), 2)
Ejemplo n.º 7
0
 def test_Array(self):
     gc.collect()
     prt = GCTestHelper.reflectionTraverseTestArray()
     del prt
     self.assertEqual(gc.collect(), 1)
Ejemplo n.º 8
0
 def test_Cycle(self):
     gc.collect()
     prt = GCTestHelper.reflectionTraverseTestCycle()
     del prt
     self.assertEqual(gc.collect(), 0)
Ejemplo n.º 9
0
 def test_PyList(self):
     gc.collect()
     prt = GCTestHelper.reflectionTraverseTestPyList()
     del prt
     self.assertEqual(gc.collect(), 2)
Ejemplo n.º 10
0
 def test_Array(self):
     gc.collect()
     prt = GCTestHelper.reflectionTraverseTestArray()
     del prt
     self.assertEqual(gc.collect(), 1)