本文整理汇总了Python中py4j.java_gateway.JavaGateway.detach方法的典型用法代码示例。如果您正苦于以下问题:Python JavaGateway.detach方法的具体用法?Python JavaGateway.detach怎么用?Python JavaGateway.detach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类py4j.java_gateway.JavaGateway
的用法示例。
在下文中一共展示了JavaGateway.detach方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MemoryManagementText
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import detach [as 别名]
class MemoryManagementText(unittest.TestCase):
def setUp(self):
self.p = start_example_app_process()
# This is to ensure that the server is started before connecting to it!
time.sleep(1)
def tearDown(self):
safe_shutdown(self)
self.p.join()
gc.collect()
def testNoAttach(self):
self.gateway = JavaGateway()
gateway2 = JavaGateway()
sb = self.gateway.jvm.java.lang.StringBuffer()
sb.append('Hello World')
self.gateway.shutdown()
try:
sb.append('Python')
self.fail('Should have failed')
except Exception:
self.assertTrue(True)
try:
sb2 = gateway2.jvm.java.lang.StringBuffer()
sb2.append('Python')
self.fail('Should have failed')
except Exception:
self.assertTrue(True)
def testDetach(self):
self.gateway = JavaGateway()
gc.collect()
finalizers_size_start = len(ThreadSafeFinalizer.finalizers)
sb = self.gateway.jvm.java.lang.StringBuffer()
sb.append('Hello World')
self.gateway.detach(sb)
sb2 = self.gateway.jvm.java.lang.StringBuffer()
sb2.append('Hello World')
sb2._detach()
gc.collect()
self.assertEqual(len(ThreadSafeFinalizer.finalizers) -
finalizers_size_start, 0)
self.gateway.shutdown()
示例2: MemoryManagementTest
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import detach [as 别名]
class MemoryManagementTest(unittest.TestCase):
def setUp(self):
self.p = start_example_app_process()
def tearDown(self):
safe_shutdown(self)
self.p.join()
gc.collect()
def testNoAttach(self):
self.gateway = JavaGateway()
gateway2 = JavaGateway()
sb = self.gateway.jvm.java.lang.StringBuffer()
sb.append("Hello World")
self.gateway.shutdown()
self.assertRaises(Exception, lambda: sb.append("Python"))
self.assertRaises(
Exception, lambda: gateway2.jvm.java.lang.StringBuffer())
def testDetach(self):
self.gateway = JavaGateway()
gc.collect()
finalizers_size_start = len(ThreadSafeFinalizer.finalizers)
sb = self.gateway.jvm.java.lang.StringBuffer()
sb.append("Hello World")
self.gateway.detach(sb)
sb2 = self.gateway.jvm.java.lang.StringBuffer()
sb2.append("Hello World")
sb2._detach()
gc.collect()
self.assertEqual(
len(ThreadSafeFinalizer.finalizers) - finalizers_size_start, 0)
self.gateway.shutdown()
示例3: MemoryManagementTest
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import detach [as 别名]
class MemoryManagementTest(unittest.TestCase):
def setUp(self):
ThreadSafeFinalizer.clear_finalizers(True)
self.p = start_example_app_process()
def tearDown(self):
safe_shutdown(self)
self.p.join()
gc.collect()
def testNoAttach(self):
self.gateway = JavaGateway()
gateway2 = JavaGateway()
sb = self.gateway.jvm.java.lang.StringBuffer()
sb.append("Hello World")
self.gateway.shutdown()
self.assertRaises(Exception, lambda: sb.append("Python"))
self.assertRaises(
Exception, lambda: gateway2.jvm.java.lang.StringBuffer())
def testDetach(self):
self.gateway = JavaGateway()
gc.collect()
finalizers_size_start = len(ThreadSafeFinalizer.finalizers)
sb = self.gateway.jvm.java.lang.StringBuffer()
sb.append("Hello World")
self.gateway.detach(sb)
sb2 = self.gateway.jvm.java.lang.StringBuffer()
sb2.append("Hello World")
sb2._detach()
gc.collect()
self.assertEqual(
len(ThreadSafeFinalizer.finalizers) - finalizers_size_start, 0)
self.gateway.shutdown()
def testGCCollect(self):
self.gateway = JavaGateway()
gc.collect()
finalizers_size_start = len(ThreadSafeFinalizer.finalizers)
def internal():
sb = self.gateway.jvm.java.lang.StringBuffer()
sb.append("Hello World")
sb2 = self.gateway.jvm.java.lang.StringBuffer()
sb2.append("Hello World")
finalizers_size_middle = len(ThreadSafeFinalizer.finalizers)
return finalizers_size_middle
finalizers_size_middle = internal()
gc.collect()
# Before collection: two objects created + two returned objects (append
# returns a stringbuffer reference for easy chaining).
self.assertEqual(finalizers_size_middle, 4)
# Assert after collection
self.assertEqual(
len(ThreadSafeFinalizer.finalizers) - finalizers_size_start, 0)
self.gateway.shutdown()
def testGCCollectNoMemoryManagement(self):
self.gateway = JavaGateway(
gateway_parameters=GatewayParameters(
enable_memory_management=False))
gc.collect()
# Should have nothing in the finalizers
self.assertEqual(len(ThreadSafeFinalizer.finalizers), 0)
def internal():
sb = self.gateway.jvm.java.lang.StringBuffer()
sb.append("Hello World")
sb2 = self.gateway.jvm.java.lang.StringBuffer()
sb2.append("Hello World")
finalizers_size_middle = len(ThreadSafeFinalizer.finalizers)
return finalizers_size_middle
finalizers_size_middle = internal()
gc.collect()
# Before collection: two objects created + two returned objects (append
# returns a stringbuffer reference for easy chaining).
self.assertEqual(finalizers_size_middle, 0)
# Assert after collection
self.assertEqual(len(ThreadSafeFinalizer.finalizers), 0)
self.gateway.shutdown()