Python java.lang.Runnable() Examples

The following are 21 code examples of java.lang.Runnable(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module java.lang , or try the search function .
Example #1
Source File: test_traceback_jy.py    From CTFCrackTools with GNU General Public License v3.0 6 votes vote down vote up
def test_tb_across_threads(self):
        if not test_support.is_jython:
            return

        # http://bugs.jython.org/issue1533624
        class PyRunnable(Runnable):
            def run(self):
                raise TypeError('this is only a test')
        try:
            EventQueue.invokeAndWait(PyRunnable())
        except TypeError:
            self.assertEqual(tb_info(),
                             [('test_tb_across_threads',
                               'EventQueue.invokeAndWait(PyRunnable())'),
                              ('run',
                               "raise TypeError('this is only a test')")])
        else:
            self.fail('Expected TypeError') 
Example #2
Source File: test_proxy.py    From chaquopy with MIT License 6 votes vote down vote up
def test_dynamic_errors(self):
        from java.lang import Object, Runnable
        with self.assertRaisesRegexp(TypeError, "'hello' is not a Java interface"):
            class P1(dynamic_proxy("hello")):
                pass
        with self.assertRaisesRegexp(TypeError,
                                     "<class 'java.lang.Object'> is not a Java interface"):
            class P2(dynamic_proxy(Object)):
                pass
        with self.assertRaisesRegexp(TypeError, "<class 'chaquopy.test.test_proxy.P3'> "
                                     "is not a Java interface"):
            class P3(dynamic_proxy(Runnable)):
                pass
            class P4(dynamic_proxy(P3)):
                pass

        with self.assertRaisesRegexp(TypeError, "dynamic_proxy must be used first in class bases"):
            class B(object):
                pass
            class P5(B, dynamic_proxy(Runnable)):
                pass
        with self.assertRaisesRegexp(TypeError,
                                     "dynamic_proxy can only be used once in class bases"):
            class P6(dynamic_proxy(Runnable), dynamic_proxy(Runnable)):
                pass 
Example #3
Source File: test_proxy.py    From chaquopy with MIT License 6 votes vote down vote up
def test_exception_in_init(self):
        from java.lang import Runnable
        ref_line_no = traceback.extract_stack()[-1][1]  # Line number of THIS line.
        class C(dynamic_proxy(Runnable)):
            def run(self):
                from . import exception_in_init  # noqa: F401

        c = C()
        try:
            cast(Runnable, c).run()
        except PyException as e:
            self.assertEqual("ValueError: Exception in __init__.py", e.getMessage())
            self.assertHasFrames(e, [
                ("<python>.chaquopy.test.exception_in_init", "<module>", "__init__.py", 3),
                ("<python>.java.chaquopy", "import_override", "import.pxi", None),
                ("<python>.chaquopy.test.test_proxy", "run", "test_proxy.py", ref_line_no + 3),
                ("com.chaquo.python.PyObject", "callAttrThrows", None, None)])

    # Checks that the given Java exception has the given frames in the given order (ignoring
    # any other frames before, between and after). 
Example #4
Source File: test_traceback_jy.py    From CTFCrackTools-V2 with GNU General Public License v3.0 6 votes vote down vote up
def test_tb_across_threads(self):
        if not test_support.is_jython:
            return

        # http://bugs.jython.org/issue1533624
        class PyRunnable(Runnable):
            def run(self):
                raise TypeError('this is only a test')
        try:
            EventQueue.invokeAndWait(PyRunnable())
        except TypeError:
            self.assertEqual(tb_info(),
                             [('test_tb_across_threads',
                               'EventQueue.invokeAndWait(PyRunnable())'),
                              ('run',
                               "raise TypeError('this is only a test')")])
        else:
            self.fail('Expected TypeError') 
Example #5
Source File: test_traceback_jy.py    From medicare-demo with Apache License 2.0 6 votes vote down vote up
def test_tb_across_threads(self):
        if not test_support.is_jython:
            return

        # http://bugs.jython.org/issue1533624
        class PyRunnable(Runnable):
            def run(self):
                raise TypeError('this is only a test')
        try:
            EventQueue.invokeAndWait(PyRunnable())
        except TypeError:
            self.assertEqual(tb_info(),
                             [('test_tb_across_threads',
                               'EventQueue.invokeAndWait(PyRunnable())'),
                              ('run',
                               "raise TypeError('this is only a test')")])
        else:
            self.fail('Expected TypeError') 
Example #6
Source File: test_proxy.py    From chaquopy with MIT License 5 votes vote down vote up
def test_direct_inherit(self):
        from java.lang import Object, Runnable
        for base in [Object, Runnable]:
            with self.assertRaisesRegexp(TypeError, "Java classes can only be inherited using "
                                         "static_proxy or dynamic_proxy"):
                class P(base):
                    pass 
Example #7
Source File: test_thread_jy.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_make_synchronized(self):
        doneSignal = CountDownLatch(10)
        class SynchedRunnable(Runnable):
            i = 0
            def run(self):
                self.i += 1
                doneSignal.countDown()
            run = synchronize.make_synchronized(run)
        runner = SynchedRunnable()
        for _ in xrange(10):
            Thread(runner).start()
        doneSignal.await()
        self.assertEquals(10, runner.i) 
Example #8
Source File: test_thread_jy.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_make_synchronized(self):
        doneSignal = CountDownLatch(10)
        class SynchedRunnable(Runnable):
            i = 0
            def run(self):
                self.i += 1
                doneSignal.countDown()
            run = synchronize.make_synchronized(run)
        runner = SynchedRunnable()
        for _ in xrange(10):
            Thread(runner).start()
        doneSignal.await()
        self.assertEquals(10, runner.i) 
Example #9
Source File: test_thread_jy.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def test_make_synchronized(self):
        doneSignal = CountDownLatch(10)
        class SynchedRunnable(Runnable):
            i = 0
            def run(self):
                self.i += 1
                doneSignal.countDown()
            run = synchronize.make_synchronized(run)
        runner = SynchedRunnable()
        for _ in xrange(10):
            Thread(runner).start()
        doneSignal.await()
        self.assertEquals(10, runner.i) 
Example #10
Source File: test_proxy.py    From chaquopy with MIT License 5 votes vote down vote up
def test_return(self):
        from java.lang import Runnable, ClassCastException, NullPointerException
        class C(dynamic_proxy(Runnable, TP.Adder, TP.GetString)):
            def run(self):
                return self.result  # returns void
            def add(self, x):
                return self.result  # returns int
            def getString(self):
                return self.result  # returns String

        c = C()
        c_Runnable, c_Adder, c_GS = [cast(cls, c) for cls in [Runnable, TP.Adder, TP.GetString]]
        c.result = None
        self.assertIsNone(c_Runnable.run())
        with self.assertRaises(NullPointerException):
            c_Adder.add(42)
        self.assertIsNone(c_GS.getString())

        c.result = 42
        with self.assertRaisesRegexp(ClassCastException, "Cannot convert int object to void"):
            c_Runnable.run()
        self.assertEqual(42, c_Adder.add(99))
        with self.assertRaisesRegexp(ClassCastException, "Cannot convert int object to "
                                     "java.lang.String"):
            c_GS.getString()

        c.result = "hello"
        with self.assertRaisesRegexp(ClassCastException, "Cannot convert str object to void"):
            c_Runnable.run()
        with self.assertRaisesRegexp(ClassCastException, "Cannot convert str object to "
                                     "java.lang.Integer"):
            c_Adder.add(99)
        self.assertEqual("hello", c_GS.getString()) 
Example #11
Source File: test_static_proxy.py    From chaquopy with MIT License 5 votes vote down vote up
def test_wrong_bases(self):
        with self.assertRaisesRegexp(TypeError, "expected extends java.lang.Object, but Java "
                                     "class actually extends java.lang.Exception"):
            class WrongExtends(static_proxy(package="com.chaquo.python.static_proxy")):
                pass

        from java.lang import Runnable
        with self.assertRaisesRegexp(TypeError, r"expected implements \['java.lang.Runnable', "
                                     r"'com.chaquo.python.StaticProxy'], but Java class actually "
                                     r"implements \[]"):
            class WrongImplements(static_proxy(None, Runnable,
                                               package="com.chaquo.python.static_proxy")):
                pass 
Example #12
Source File: test_gc_jy.py    From CTFCrackTools-V2 with GNU General Public License v3.0 4 votes vote down vote up
def test_finalization_preprocess_and_postprocess(self):
        # Note that this test is done here again (already was in another class
        # in this module), to see that everything works as it should also with
        # a different flag-context.
        comments = []
        self0 = self
        class A:
            def __del__(self):
                self0.assertIn("run PreProcess", comments)
                comments.append("A del")
                # let's simulate a time-consuming finalizer
                # to ensure that post finalization processing
                # is sensitive to this
                time.sleep(0.5)
                comments.append("A del done")

        class PreProcess(Runnable):
            def run(self):
                self0.assertEqual(comments, [])
                comments.append("run PreProcess")

        class PostProcess(Runnable):
            def run(self):
                self0.assertIn("run PreProcess", comments)
                self0.assertIn("A del", comments)
                self0.assertIn("A del done", comments)
                comments.append("run PostProcess")

        a = A()
        a = None
        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)
        # Note that order matters here:
        # If the flag gc.DONT_FINALIZE_RESURRECTED_OBJECTS is used,
        # gc.registerPostFinalizationProcess(postPr, 0) would lead to failure,
        # because postPr asserts that a's finalizer already ran. Since
        # DONT_FINALIZE_RESURRECTED_OBJECTS also inserted a postprocess,
        # to perform delayed finalization, the 0-index would prepend postPr
        # before the process that actually runs the finalizers.
        System.gc()
        # we wait a bit longer here, since PostProcess runs asynchronous
        # and must wait for the finalizer of A
        time.sleep(2)
        self.assertIn("run PostProcess", comments)
        comments = []
        gc.unregisterPreFinalizationProcess(prePr)
        gc.unregisterPostFinalizationProcess(postPr) 
Example #13
Source File: test_gc_jy.py    From CTFCrackTools-V2 with GNU General Public License v3.0 4 votes vote down vote up
def test_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) 
Example #14
Source File: test_gc_jy.py    From CTFCrackTools-V2 with GNU General Public License v3.0 4 votes vote down vote up
def test_finalization_preprocess_and_postprocess(self):
        # Note that this test is done here again (already was in another class
        # in this module), to see that everything works as it should also with
        # a different flag-context.
        comments = []
        self0 = self
        class A:
            def __del__(self):
                self0.assertIn("run PreProcess", comments)
                comments.append("A del")
                # let's simulate a time-consuming finalizer
                # to ensure that post finalization processing
                # is sensitive to this
                time.sleep(0.5)
                comments.append("A del done")

        class PreProcess(Runnable):
            def run(self):
                self0.assertEqual(comments, [])
                comments.append("run PreProcess")

        class PostProcess(Runnable):
            def run(self):
                self0.assertIn("run PreProcess", comments)
                self0.assertIn("A del", comments)
                self0.assertIn("A del done", comments)
                comments.append("run PostProcess")

        a = A()
        a = None
        prePr = PreProcess()
        postPr = PostProcess()
        time.sleep(2) #   <- to avoid that the newly registered processes
                      #      become subject to previous run
        gc.registerPreFinalizationProcess(prePr)
        gc.registerPostFinalizationProcess(postPr)
        # Note that order matters here:
        # If the flag gc.DONT_FINALIZE_RESURRECTED_OBJECTS is used,
        # gc.registerPostFinalizationProcess(postPr, 0) would lead to failure,
        # because postPr asserts that a's finalizer already ran. Since
        # DONT_FINALIZE_RESURRECTED_OBJECTS also inserted a postprocess,
        # to perform delayed finalization, the 0-index would prepend postPr
        # before the process that actually runs the finalizers.
        System.gc()
        # we wait a bit longer here, since PostProcess runs asynchronous
        # and must wait for the finalizer of A
        time.sleep(2)
        self.assertIn("run PostProcess", comments)
        comments = []
        gc.unregisterPreFinalizationProcess(prePr)
        gc.unregisterPostFinalizationProcess(postPr) 
Example #15
Source File: test_gc_jy.py    From CTFCrackTools-V2 with GNU General Public License v3.0 4 votes vote down vote up
def test_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) 
Example #16
Source File: test_gc_jy.py    From CTFCrackTools-V2 with GNU General Public License v3.0 4 votes vote down vote up
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) 
Example #17
Source File: test_gc_jy.py    From CTFCrackTools with GNU General Public License v3.0 4 votes vote down vote up
def test_finalization_preprocess_and_postprocess(self):
        # Note that this test is done here again (already was in another class
        # in this module), to see that everything works as it should also with
        # a different flag-context.
        comments = []
        self0 = self
        class A:
            def __del__(self):
                self0.assertIn("run PreProcess", comments)
                comments.append("A del")
                # let's simulate a time-consuming finalizer
                # to ensure that post finalization processing
                # is sensitive to this
                time.sleep(0.5)
                comments.append("A del done")

        class PreProcess(Runnable):
            def run(self):
                self0.assertEqual(comments, [])
                comments.append("run PreProcess")

        class PostProcess(Runnable):
            def run(self):
                self0.assertIn("run PreProcess", comments)
                self0.assertIn("A del", comments)
                self0.assertIn("A del done", comments)
                comments.append("run PostProcess")

        a = A()
        a = None
        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)
        # Note that order matters here:
        # If the flag gc.DONT_FINALIZE_RESURRECTED_OBJECTS is used,
        # gc.registerPostFinalizationProcess(postPr, 0) would lead to failure,
        # because postPr asserts that a's finalizer already ran. Since
        # DONT_FINALIZE_RESURRECTED_OBJECTS also inserted a postprocess,
        # to perform delayed finalization, the 0-index would prepend postPr
        # before the process that actually runs the finalizers.
        System.gc()
        # we wait a bit longer here, since PostProcess runs asynchronous
        # and must wait for the finalizer of A
        time.sleep(2)
        self.assertIn("run PostProcess", comments)
        comments = []
        gc.unregisterPreFinalizationProcess(prePr)
        gc.unregisterPostFinalizationProcess(postPr) 
Example #18
Source File: test_gc_jy.py    From CTFCrackTools with GNU General Public License v3.0 4 votes vote down vote up
def test_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) 
Example #19
Source File: test_gc_jy.py    From CTFCrackTools with GNU General Public License v3.0 4 votes vote down vote up
def test_finalization_preprocess_and_postprocess(self):
        # Note that this test is done here again (already was in another class
        # in this module), to see that everything works as it should also with
        # a different flag-context.
        comments = []
        self0 = self
        class A:
            def __del__(self):
                self0.assertIn("run PreProcess", comments)
                comments.append("A del")
                # let's simulate a time-consuming finalizer
                # to ensure that post finalization processing
                # is sensitive to this
                time.sleep(0.5)
                comments.append("A del done")

        class PreProcess(Runnable):
            def run(self):
                self0.assertEqual(comments, [])
                comments.append("run PreProcess")

        class PostProcess(Runnable):
            def run(self):
                self0.assertIn("run PreProcess", comments)
                self0.assertIn("A del", comments)
                self0.assertIn("A del done", comments)
                comments.append("run PostProcess")

        a = A()
        a = None
        prePr = PreProcess()
        postPr = PostProcess()
        time.sleep(2) #   <- to avoid that the newly registered processes
                      #      become subject to previous run
        gc.registerPreFinalizationProcess(prePr)
        gc.registerPostFinalizationProcess(postPr)
        # Note that order matters here:
        # If the flag gc.DONT_FINALIZE_RESURRECTED_OBJECTS is used,
        # gc.registerPostFinalizationProcess(postPr, 0) would lead to failure,
        # because postPr asserts that a's finalizer already ran. Since
        # DONT_FINALIZE_RESURRECTED_OBJECTS also inserted a postprocess,
        # to perform delayed finalization, the 0-index would prepend postPr
        # before the process that actually runs the finalizers.
        System.gc()
        # we wait a bit longer here, since PostProcess runs asynchronous
        # and must wait for the finalizer of A
        time.sleep(2)
        self.assertIn("run PostProcess", comments)
        comments = []
        gc.unregisterPreFinalizationProcess(prePr)
        gc.unregisterPostFinalizationProcess(postPr) 
Example #20
Source File: test_gc_jy.py    From CTFCrackTools with GNU General Public License v3.0 4 votes vote down vote up
def test_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) 
Example #21
Source File: test_gc_jy.py    From CTFCrackTools with GNU General Public License v3.0 4 votes vote down vote up
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)