本文整理汇总了Python中py4j.java_gateway.JavaGateway方法的典型用法代码示例。如果您正苦于以下问题:Python java_gateway.JavaGateway方法的具体用法?Python java_gateway.JavaGateway怎么用?Python java_gateway.JavaGateway使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类py4j.java_gateway
的用法示例。
在下文中一共展示了java_gateway.JavaGateway方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_gateway
# 需要导入模块: from py4j import java_gateway [as 别名]
# 或者: from py4j.java_gateway import JavaGateway [as 别名]
def get_gateway():
# type: () -> JavaGateway
global _gateway
global _lock
with _lock:
if _gateway is None:
# if Java Gateway is already running
if 'PYFLINK_GATEWAY_PORT' in os.environ:
gateway_port = int(os.environ['PYFLINK_GATEWAY_PORT'])
gateway_param = GatewayParameters(port=gateway_port, auto_convert=True)
_gateway = JavaGateway(gateway_parameters=gateway_param)
else:
_gateway = launch_gateway()
# import the flink view
import_flink_view(_gateway)
install_exception_handler()
return _gateway
示例2: sxstart
# 需要导入模块: from py4j import java_gateway [as 别名]
# 或者: from py4j.java_gateway import JavaGateway [as 别名]
def sxstart():
from py4j.java_gateway import JavaGateway
try:
JavaGW = JavaGateway()
SXPKG = JavaGW.jvm.org.sikuli
return (JavaGW, SXPKG)
except:
print("sxstart: SikuliX not running")
exit(1)
示例3: gateway
# 需要导入模块: from py4j import java_gateway [as 别名]
# 或者: from py4j.java_gateway import JavaGateway [as 别名]
def gateway(self):
"""
Returns the :class:`~py4j.java_gateway.JavaGateway` object, only if
the shared library is a Java archive, otherwise returns :data:`None`.
"""
return self._gateway
示例4: __init__
# 需要导入模块: from py4j import java_gateway [as 别名]
# 或者: from py4j.java_gateway import JavaGateway [as 别名]
def __init__(self):
self.gateway = JavaGateway()
self.analyzer = self.gateway.entry_point
self.pos_tags = self._pos_tags()
self.feat_tags = self._feat_tags()
self.chunk_tags = self._chunk_tags()
self.synchunk_tags = self._synchunk_tags()
示例5: launch_gateway
# 需要导入模块: from py4j import java_gateway [as 别名]
# 或者: from py4j.java_gateway import JavaGateway [as 别名]
def launch_gateway(cls):
jars_dir = os.environ["PYPMML_JARS_DIR"] if "PYPMML_JARS_DIR" in os.environ else \
path.join(path.dirname(path.abspath(__file__)), 'jars')
launch_classpath = path.join(jars_dir, "*")
_port = launch_gateway(classpath=launch_classpath, die_on_exit=True)
gateway = JavaGateway(
gateway_parameters=GatewayParameters(port=_port,
auto_convert=True))
return gateway
示例6: launch_gateway
# 需要导入模块: from py4j import java_gateway [as 别名]
# 或者: from py4j.java_gateway import JavaGateway [as 别名]
def launch_gateway():
# type: () -> JavaGateway
"""
launch jvm gateway
"""
FLINK_HOME = _find_flink_home()
# TODO windows support
on_windows = platform.system() == "Windows"
if on_windows:
raise Exception("Windows system is not supported currently.")
script = "./bin/pyflink-gateway-server.sh"
command = [os.path.join(FLINK_HOME, script)]
command += ['-c', 'org.apache.flink.client.python.PythonGatewayServer']
submit_args = os.environ.get("SUBMIT_ARGS", "local")
command += shlex.split(submit_args)
# Create a temporary directory where the gateway server should write the connection information.
conn_info_dir = tempfile.mkdtemp()
try:
fd, conn_info_file = tempfile.mkstemp(dir=conn_info_dir)
os.close(fd)
os.unlink(conn_info_file)
env = dict(os.environ)
env["_PYFLINK_CONN_INFO_PATH"] = conn_info_file
def preexec_func():
# ignore ctrl-c / SIGINT
signal.signal(signal.SIGINT, signal.SIG_IGN)
# Launch the Java gateway.
# We open a pipe to stdin so that the Java gateway can die when the pipe is broken
p = Popen(command, stdin=PIPE, preexec_fn=preexec_func, env=env)
while not p.poll() and not os.path.isfile(conn_info_file):
time.sleep(0.1)
if not os.path.isfile(conn_info_file):
raise Exception("Java gateway process exited before sending its port number")
with open(conn_info_file, "rb") as info:
gateway_port = struct.unpack("!I", info.read(4))[0]
finally:
shutil.rmtree(conn_info_dir)
# Connect to the gateway
gateway = JavaGateway(
gateway_parameters=GatewayParameters(port=gateway_port, auto_convert=True))
return gateway
示例7: launch_gateway
# 需要导入模块: from py4j import java_gateway [as 别名]
# 或者: from py4j.java_gateway import JavaGateway [as 别名]
def launch_gateway():
SPARK_HOME = os.environ["SPARK_HOME"]
gateway_port = -1
if "PYSPARK_GATEWAY_PORT" in os.environ:
gateway_port = int(os.environ["PYSPARK_GATEWAY_PORT"])
else:
# Launch the Py4j gateway using Spark's run command so that we pick up the
# proper classpath and settings from spark-env.sh
on_windows = platform.system() == "Windows"
script = "./bin/spark-submit.cmd" if on_windows else "./bin/spark-submit"
submit_args = os.environ.get("PYSPARK_SUBMIT_ARGS")
submit_args = submit_args if submit_args is not None else ""
submit_args = shlex.split(submit_args)
command = [os.path.join(SPARK_HOME, script), "pyspark-shell"] + submit_args
if not on_windows:
# Don't send ctrl-c / SIGINT to the Java gateway:
def preexec_func():
signal.signal(signal.SIGINT, signal.SIG_IGN)
proc = Popen(command, stdout=PIPE, stdin=PIPE, preexec_fn=preexec_func)
else:
# preexec_fn not supported on Windows
proc = Popen(command, stdout=PIPE, stdin=PIPE)
# Determine which ephemeral port the server started on:
gateway_port = int(proc.stdout.readline())
# Create a thread to echo output from the GatewayServer, which is required
# for Java log output to show up:
class EchoOutputThread(Thread):
def __init__(self, stream):
Thread.__init__(self)
self.daemon = True
self.stream = stream
def run(self):
while True:
line = self.stream.readline()
sys.stderr.write(line)
EchoOutputThread(proc.stdout).start()
# Connect to the gateway
gateway = JavaGateway(GatewayClient(port=gateway_port), auto_convert=False)
# Import the classes used by PySpark
java_import(gateway.jvm, "org.apache.spark.SparkConf")
java_import(gateway.jvm, "org.apache.spark.api.java.*")
java_import(gateway.jvm, "org.apache.spark.api.python.*")
java_import(gateway.jvm, "org.apache.spark.mllib.api.python.*")
java_import(gateway.jvm, "org.apache.spark.sql.SQLContext")
java_import(gateway.jvm, "org.apache.spark.sql.hive.HiveContext")
java_import(gateway.jvm, "org.apache.spark.sql.hive.LocalHiveContext")
java_import(gateway.jvm, "org.apache.spark.sql.hive.TestHiveContext")
java_import(gateway.jvm, "scala.Tuple2")
return gateway