本文整理汇总了Python中py4j.java_gateway.JavaGateway.launch_gateway方法的典型用法代码示例。如果您正苦于以下问题:Python JavaGateway.launch_gateway方法的具体用法?Python JavaGateway.launch_gateway怎么用?Python JavaGateway.launch_gateway使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类py4j.java_gateway.JavaGateway
的用法示例。
在下文中一共展示了JavaGateway.launch_gateway方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import launch_gateway [as 别名]
def __init__(self):
my_logger = getLogger('py4j')
handler = StreamHandler()
handler.setLevel(DEBUG)
my_logger.setLevel(DEBUG)
my_logger.addHandler(handler)
if glob.glob("./lib/py4j-0.8.1.jar"):
jarpath = glob.glob("./lib/py4j-0.8.1.jar")[0]
elif glob.glob("./py4j-0.8.1.jar"):
jarpath = glob.glob("./py4j-0.8.1")
else:
jarpath = None
if glob.glob("./lib/droidnavi-gateway-server*"):
classpath = glob.glob("./lib/droidnavi-gateway-server*")
elif glob.glob("./droidnavi-gateway-server*"):
classpath = glob.glob("./droidnavi-gateway-server*")[0]
else:
classpath = None
self.__gateway = JavaGateway.launch_gateway(jarpath=jarpath, classpath=classpath, die_on_exit=True)
print self.__gateway
app = QtGui.QApplication(sys.argv)
mainWindow = MainWindow(self.__gateway)
sys.exit(app.exec_())
示例2: testRedirectToFile
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import launch_gateway [as 别名]
def testRedirectToFile(self):
(_, outpath) = tempfile.mkstemp(text=True)
(_, errpath) = tempfile.mkstemp(text=True)
stdout = open(outpath, "w")
stderr = open(errpath, "w")
try:
self.gateway = JavaGateway.launch_gateway(
redirect_stdout=stdout, redirect_stderr=stderr)
for i in range(10):
self.gateway.jvm.System.out.println("Test")
self.gateway.jvm.System.err.println("Test2")
# Should not be necessary
quiet_close(stdout)
quiet_close(stderr)
# Test that the redirect files were written to correctly
with open(outpath, "r") as stdout:
lines = stdout.readlines()
self.assertEqual(10, len(lines))
self.assertEqual("Test\n", lines[0])
with open(errpath, "r") as stderr:
lines = stderr.readlines()
self.assertEqual(10, len(lines))
self.assertEqual("Test2\n", lines[0])
finally:
os.unlink(outpath)
os.unlink(errpath)
示例3: testGatewayAuth
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import launch_gateway [as 别名]
def testGatewayAuth(self):
self.gateway = JavaGateway.launch_gateway(enable_auth=True)
# Make sure the default client can connect to the server.
klass = self.gateway.jvm.java.lang.String
help_page = self.gateway.help(klass, short_name=True, display=False)
self.assertGreater(len(help_page), 1)
# Replace the client with one that does not authenticate.
# Make sure it fails.
bad_client = GatewayClient(gateway_parameters=GatewayParameters(
address=self.gateway.gateway_parameters.address,
port=self.gateway.gateway_parameters.port))
self.gateway.set_gateway_client(bad_client)
try:
self.gateway.help(klass, short_name=True, display=False)
self.fail("Expected failure to communicate with gateway server.")
except Exception:
# Expected
pass
finally:
# Restore a good client. This allows the gateway to be shut down.
good_client = GatewayClient(
gateway_parameters=self.gateway.gateway_parameters)
self.gateway.set_gateway_client(good_client)
示例4: clearschedule
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import launch_gateway [as 别名]
def clearschedule(self, cfname, counter):
gateway = JavaGateway.launch_gateway(port=9009,jarpath="/home/ubuntu/py4j0.8.jar", classpath="/home/ubuntu/py-tpcc-master/pytpcc/")
gateway = JavaGateway(GatewayParameters(port=9009))
interface_object = gateway.entry_point
millis = int(round(time.time() * 1000))
#uuid = gateway.jvm.java.util.UUID()
clId = gateway.jvm.java.util.UUID.randomUUID()
l = 20
interface_object.clearscheduleAndQueueTPCC(20, cfname, 1, clId, millis)
示例5: __init__
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import launch_gateway [as 别名]
def __init__(self, driver_name, url, username, password):
if 'py4j' not in sys.modules:
raise Exception('Required py4j module is not imported.')
self.gateway = JavaGateway.launch_gateway(classpath=os.environ['CLASSPATH'])
self.jdbc_driver = driver_name
self.db_url = url
self.username = username
self.password = password
self.conn = None
示例6: schedule
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import launch_gateway [as 别名]
def schedule(self, cfname, counter):
gateway = JavaGateway.launch_gateway(port=9009,jarpath="/home/ubuntu/py4j0.8.jar", classpath="/home/ubuntu/py-tpcc-master/pytpcc/")
gateway = JavaGateway(GatewayParameters(port=9009))
#logging.info("***before launch gateway in schedule")
#logging.info("***before printing values in schedule")
interface_object = gateway.entry_point
millis = int(round(time.time() * 1000))
#logging.info("***value of millis: ", %millis)
#uuid = gateway.jvm.java.util.UUID()
clId = gateway.jvm.java.util.UUID.randomUUID()
logging.debug("***value of clId: ",clId)
l = 20
#interface_object.scheduleAndQueueTPCC()
interface_object.scheduleAndQueueTPCC(20, cfname, 1, clId, millis)
示例7: testRedirectToDeque
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import launch_gateway [as 别名]
def testRedirectToDeque(self):
qout = deque()
qerr = deque()
self.gateway = JavaGateway.launch_gateway(
redirect_stdout=qout, redirect_stderr=qerr)
for i in range(10):
self.gateway.jvm.System.out.println("Test")
self.gateway.jvm.System.err.println("Test2")
sleep()
for i in range(10):
self.assertEqual("Test\n", qout.pop())
self.assertEqual("Test2\n", qerr.pop())
self.assertEqual(0, len(qout))
self.assertEqual(0, len(qerr))
示例8: testRedirectToQueue
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import launch_gateway [as 别名]
def testRedirectToQueue(self):
qout = Queue()
qerr = Queue()
self.gateway = JavaGateway.launch_gateway(
redirect_stdout=qout, redirect_stderr=qerr)
for i in range(10):
self.gateway.jvm.System.out.println("Test")
self.gateway.jvm.System.err.println("Test2")
sleep()
for i in range(10):
self.assertEqual("Test\n", qout.get())
self.assertEqual("Test2\n", qerr.get())
self.assertTrue(qout.empty)
self.assertTrue(qerr.empty)
示例9: test_gateway_close
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import launch_gateway [as 别名]
async def test_gateway_close():
"""
Test that shutting down the context does not shut down the Java side gateway if launch_jvm was
False.
"""
gateway = JavaGateway.launch_gateway()
async with Context() as context:
await Py4JComponent(gateway={'port': gateway.gateway_parameters.port},
launch_jvm=False).start(context)
context.java.jvm.java.lang.System.setProperty('TEST_VALUE', 'abc')
assert gateway.jvm.java.lang.System.getProperty('TEST_VALUE') == 'abc'
gateway.shutdown()
示例10: testRedirectToDeque
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import launch_gateway [as 别名]
def testRedirectToDeque(self):
end = os.linesep
qout = deque()
qerr = deque()
self.gateway = JavaGateway.launch_gateway(
redirect_stdout=qout, redirect_stderr=qerr)
for i in range(10):
self.gateway.jvm.System.out.println("Test")
self.gateway.jvm.System.err.println("Test2")
sleep()
for i in range(10):
self.assertEqual("Test{0}".format(end), qout.pop())
# Assert IN because some Java/OS outputs some garbage on stderr.
line = qerr.pop()
if stderr_is_polluted(line):
line = qerr.pop()
self.assertEqual("Test2{0}".format(end), line)
self.assertEqual(0, len(qout))
self.assertEqual(0, len(qerr))
示例11: testRedirectToFile
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import launch_gateway [as 别名]
def testRedirectToFile(self):
end = os.linesep
(out_handle, outpath) = tempfile.mkstemp(text=True)
(err_handle, errpath) = tempfile.mkstemp(text=True)
stdout = open(outpath, "w")
stderr = open(errpath, "w")
try:
self.gateway = JavaGateway.launch_gateway(
redirect_stdout=stdout, redirect_stderr=stderr)
for i in range(10):
self.gateway.jvm.System.out.println("Test")
self.gateway.jvm.System.err.println("Test2")
self.gateway.shutdown()
sleep()
# Should not be necessary
quiet_close(stdout)
quiet_close(stderr)
# Test that the redirect files were written to correctly
with open(outpath, "r") as stdout:
lines = stdout.readlines()
self.assertEqual(10, len(lines))
self.assertEqual("Test{0}".format(end), lines[0])
with open(errpath, "r") as stderr:
lines = stderr.readlines()
if not stderr_is_polluted(lines[0]):
self.assertEqual(10, len(lines))
# XXX Apparently, it's \n by default even on windows...
# Go figure
self.assertEqual("Test2\n", lines[0])
finally:
os.close(out_handle)
os.close(err_handle)
os.unlink(outpath)
os.unlink(errpath)
示例12: get_caller_dir
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import launch_gateway [as 别名]
from py4j.java_gateway import JavaGateway
from wavesynlib.languagecenter.utils import get_caller_dir
itext_filename = None
self_dir = get_caller_dir()
for filename in os.listdir(self_dir):
if re.match('itextpdf.*\.jar', filename): # iText jar is found.
itext_filename = os.path.join(self_dir, filename)
if itext_filename is None:
raise ImportError('Cannot find iText jar file.')
_gateway = JavaGateway.launch_gateway(die_on_exit=True, classpath=itext_filename)
class PdfManipulator(object):
'''
Supported Commands:
IO Commands:
read_from_file: read a PDF file, arguments: filename, return a stream;
write_to_file: write to a PDF file, arguments: filename.
Manipulation Commands:
append: append one or more PDF files to the end of the current stream;
arguments: filelist (the list of the PDF file names);
remove_pages: remove pages from the stream,
arguments: pagenum (the number of the pages which will be removed);
remove_annotations: remove the annotations of the current stream.
Command Pipeline Example:
示例13: testRedirectToNullOtherProcessGroup
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import launch_gateway [as 别名]
def testRedirectToNullOtherProcessGroup(self):
self.gateway = JavaGateway.launch_gateway(
create_new_process_group=True)
for i in range(4097): # Hangs if not properly redirected
self.gateway.jvm.System.out.println("Test")
示例14: testRedirectToNull
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import launch_gateway [as 别名]
def testRedirectToNull(self):
self.gateway = JavaGateway.launch_gateway()
for i in range(4097): # Hangs if not properly redirected
self.gateway.jvm.System.out.println("Test")
示例15: testJavaopts
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import launch_gateway [as 别名]
def testJavaopts(self):
self.gateway = JavaGateway.launch_gateway(javaopts=["-Xmx64m"])
self.assertTrue(self.gateway.jvm)