本文整理汇总了Python中java.lang.Runnable方法的典型用法代码示例。如果您正苦于以下问题:Python lang.Runnable方法的具体用法?Python lang.Runnable怎么用?Python lang.Runnable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang
的用法示例。
在下文中一共展示了lang.Runnable方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dynamic_errors
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Runnable [as 别名]
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
示例2: test_exception_in_init
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Runnable [as 别名]
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).
示例3: test_tb_across_threads
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Runnable [as 别名]
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')
示例4: test_wrong_bases
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Runnable [as 别名]
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
示例5: test_direct_inherit
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Runnable [as 别名]
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
示例6: test_return
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Runnable [as 别名]
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())
示例7: test_make_synchronized
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Runnable [as 别名]
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)
示例8: test_finalization_preprocess_and_postprocess
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Runnable [as 别名]
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)
示例9: test_with_extern_NonPyObjectFinalizer_that_notifies_gc
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Runnable [as 别名]
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)
示例10: test_forced_with_extern_NonPyObjectFinalizer_that_notifies_gc
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Runnable [as 别名]
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)