當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。