当前位置: 首页>>代码示例>>Python>>正文


Python java_gateway.JavaGateway方法代码示例

本文整理汇总了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 
开发者ID:huseinzol05,项目名称:Gather-Deployment,代码行数:20,代码来源:java_gateway.py

示例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) 
开发者ID:RaiMan,项目名称:sikulix4python,代码行数:11,代码来源:sxgateway.py

示例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 
开发者ID:MSLNZ,项目名称:msl-loadlib,代码行数:8,代码来源:load_library.py

示例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() 
开发者ID:gpassero,项目名称:cogroo4py,代码行数:9,代码来源:cogroo_interface.py

示例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 
开发者ID:autodeployai,项目名称:pypmml,代码行数:12,代码来源:base.py

示例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 
开发者ID:huseinzol05,项目名称:Gather-Deployment,代码行数:54,代码来源:java_gateway.py

示例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 
开发者ID:adobe-research,项目名称:spark-cluster-deployment,代码行数:56,代码来源:java_gateway.py


注:本文中的py4j.java_gateway.JavaGateway方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。