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


Python JavaGateway.close方法代码示例

本文整理汇总了Python中py4j.java_gateway.JavaGateway.close方法的典型用法代码示例。如果您正苦于以下问题:Python JavaGateway.close方法的具体用法?Python JavaGateway.close怎么用?Python JavaGateway.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在py4j.java_gateway.JavaGateway的用法示例。


在下文中一共展示了JavaGateway.close方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testCallbackServer

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import close [as 别名]
 def testCallbackServer(self):
     # A close is required to stop the thread.
     gateway = JavaGateway(
         callback_server_parameters=CallbackServerParameters())
     gateway.close()
     self.assertTrue(True)
     sleep(2)
开发者ID:bartdag,项目名称:py4j,代码行数:9,代码来源:java_gateway_test.py

示例2: shutdown_gateway

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import close [as 别名]
    def shutdown_gateway(event, gateway: JavaGateway, resource_name: str, shutdown_jvm: bool):
        if shutdown_jvm:
            gateway.shutdown()
        else:
            gateway.close()

        logger.info('Py4J gateway (%s) shut down', resource_name)
开发者ID:asphalt-framework,项目名称:asphalt-py4j,代码行数:9,代码来源:component.py

示例3: _initialize_gateway

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import close [as 别名]
    def _initialize_gateway(gateway_address):
        (host, port) = gateway_address

        callback_params = CallbackServerParameters(address=host, port=0)

        gateway = JavaGateway(GatewayClient(address=host, port=port),
                              start_callback_server=True,
                              auto_convert=True,
                              callback_server_parameters=callback_params)
        try:
            java_import(gateway.jvm, "org.apache.spark.SparkEnv")
            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.*")
            java_import(gateway.jvm, "org.apache.spark.sql.hive.*")
            java_import(gateway.jvm, "scala.Tuple2")
            java_import(gateway.jvm, "scala.collection.immutable.List")
        except Py4JError as e:
            log_error('Error while initializing java gateway: {}'.format(e))
            gateway.close()
            return None

        return gateway
开发者ID:deepsense-io,项目名称:seahorse-workflow-executor,代码行数:27,代码来源:pyexecutor.py

示例4: check_connection

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import close [as 别名]
def check_connection(gateway_parameters=None):
    test_gateway = JavaGateway(gateway_parameters=gateway_parameters)
    try:
        # Call a dummy method just to make sure we can connect to the JVM
        test_gateway.jvm.System.currentTimeMillis()
    except Py4JNetworkError:
        # We could not connect. Let"s wait a long time.
        # If it fails after that, there is a bug with our code!
        sleep(2)
    finally:
        test_gateway.close()
开发者ID:bartdag,项目名称:py4j,代码行数:13,代码来源:java_gateway_test.py

示例5: test_gateway_connection

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import close [as 别名]
def test_gateway_connection():
    test_gateway = JavaGateway()
    try:
        # Call a dummy method just to make sure we can connect to the JVM
        test_gateway.jvm.System.lineSeparator()
    except Py4JNetworkError:
        # We could not connect. Let"s wait a long time.
        # If it fails after that, there is a bug with our code!
        sleep(2)
    finally:
        test_gateway.close()
开发者ID:18600597055,项目名称:hue,代码行数:13,代码来源:java_gateway_test.py

示例6: tearDownClass

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import close [as 别名]
 def tearDownClass(cls):
     gateway = JavaGateway()
     workspace = gateway.jvm.org.eclipse.core.resources.ResourcesPlugin.\
             getWorkspace()
     root = workspace.getRoot()
     pm = gateway.jvm.org.eclipse.core.runtime.NullProgressMonitor()
     project1 = root.getProject('project1core3.0')
     project1.delete(True, True, pm)
     time.sleep(1)
     gateway.close()
     stop_eclipse()
     clean_test_dir()
开发者ID:bartdag,项目名称:recodoc2,代码行数:14,代码来源:tests.py

示例7: stop_eclipse

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import close [as 别名]
def stop_eclipse():
    gateway = JavaGateway()
    try:
        gateway.entry_point.closeEclipse()
        time.sleep(1)
        gateway.shutdown()
    except Exception:
        pass
    try:
        gateway.close()
    except Exception:
        pass
开发者ID:bartdag,项目名称:recodoc2,代码行数:14,代码来源:actions.py

示例8: check_eclipse

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import close [as 别名]
def check_eclipse():
    '''Check that Eclipse is started and that recodoc can communicate with
       it.'''
    gateway = JavaGateway()
    try:
        success = gateway.entry_point.getServer().getListeningPort() > 0
    except Exception:
        success = False

    if success:
        print('Connection to Eclipse: OK')
    else:
        print('Connection to Eclipse: ERROR')

    gateway.close()

    return success
开发者ID:bartdag,项目名称:recodoc2,代码行数:19,代码来源:actions.py

示例9: testLinkEclipseProject

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import close [as 别名]
    def testLinkEclipseProject(self):
        create_code_local('project1', 'core', '3.0')
        to_path = get_codebase_path('project1', 'core', '3.0')
        to_path = os.path.join(to_path, 'src')
        os.rmdir(to_path)
        from_path = os.path.join(settings.TESTDATA, 'testproject1', 'src')
        shutil.copytree(from_path, to_path)
        link_eclipse('project1', 'core', '3.0')

        gateway = JavaGateway()
        workspace = gateway.jvm.org.eclipse.core.resources.ResourcesPlugin.\
                getWorkspace()
        root = workspace.getRoot()
        pm = gateway.jvm.org.eclipse.core.runtime.NullProgressMonitor()
        project1 = root.getProject('project1core3.0')
        self.assertIsNotNone(project1)
        project1.delete(True, True, pm)
        time.sleep(1)
        gateway.close()
开发者ID:bartdag,项目名称:recodoc2,代码行数:21,代码来源:tests.py

示例10: link_eclipse

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import close [as 别名]
def link_eclipse(pname, bname, release):
    '''Add the Java Project created with create_code_local to the Eclipse
       workspace.'''
    project_key = pname + bname + release
    codebase_path = get_codebase_path(pname, bname, release)

    gateway = JavaGateway()
    workspace = gateway.jvm.org.eclipse.core.resources.ResourcesPlugin.\
            getWorkspace()
    root = workspace.getRoot()
    path = gateway.jvm.org.eclipse.core.runtime.Path(os.path.join(
        codebase_path, PROJECT_FILE))
    project_desc = workspace.loadProjectDescription(path)
    new_project = root.getProject(project_key)
    nmonitor = gateway.jvm.org.eclipse.core.runtime.NullProgressMonitor()
#    gateway.jvm.py4j.GatewayServer.turnLoggingOn()
    # To avoid workbench problem (don't know why it needs some time).
    time.sleep(1)
    new_project.create(project_desc, nmonitor)
    new_project.open(nmonitor)
    gateway.close()
开发者ID:bartdag,项目名称:recodoc2,代码行数:23,代码来源:actions.py

示例11: JavaGateway

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import close [as 别名]
# This script tests the star brightness commands.
# Created by Toni Sagrista


from py4j.java_gateway import JavaGateway, GatewayParameters

gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_convert=True))
gs = gateway.entry_point

gs.setStarBrightness(100.0)
gs.sleep(2)
gs.setStarBrightness(70.0)
gs.sleep(2)
gs.setStarBrightness(50.0)
gs.sleep(2)
gs.setStarBrightness(30.0)
gs.sleep(2)
gs.setStarBrightness(12.0)
gs.sleep(2)

gateway.close()
开发者ID:ari-zah,项目名称:gaiasky,代码行数:23,代码来源:starbrightness-test.py

示例12: testCallbackServer

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import close [as 别名]
 def testCallbackServer(self):
     # A close is required to stop the thread.
     gateway = JavaGateway(start_callback_server=True)
     gateway.close()
     self.assertTrue(True)
     time.sleep(1)
开发者ID:gdw2,项目名称:py4j,代码行数:8,代码来源:java_gateway_test.py

示例13: JavaParser

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import close [as 别名]
class JavaParser(object):
    '''Parses a Java codebase and creates the appropriate CodeElement.

    This parser uses multiple threads to speed up the parsing. This parser
    requires access to Eclipse/Py4J'''

    JAVA_SRC_FOLDER = 'src'

    def __init__(self, codebase, project_key, opt_input):
        '''
        :param project_key: The name of the project in the Eclipse workspace.
        :param codebase: The codebase instance to which the CodeElement will
                         be associated with.
        :param opt_input: Optional input. Not used by this parser.
        '''
        self.project_name = project_key
        self.gateway = JavaGateway()

        self.hierarchies = deque()  # list of tuples. [(parent, child, child)]
        self.codebase = codebase
        self.queue = Queue()

        self.package_kind = CodeElementKind.objects.get(kind='package')
        self.ASTParser = self.gateway.jvm.org.eclipse.jdt.core.dom.ASTParser
        self.JLS3 = self.gateway.jvm.org.eclipse.jdt.core.dom.AST.JLS3

    def _get_package_root(self):
        ResourcePlugin = self.gateway.jvm.org.eclipse.core.resources.\
                ResourcesPlugin
        workspaceRoot = ResourcePlugin.getWorkspace().getRoot()
        project = workspaceRoot.getProject(self.project_name)
        java_project = self.gateway.jvm.org.eclipse.jdt.core.JavaCore.\
                create(project)
        src_folder = project.getFolder(JavaParser.JAVA_SRC_FOLDER)
        proot = java_project.getPackageFragmentRoot(src_folder)
        return proot

    def _parse_packages(self, proot):
        packages = []
        for package in proot.getChildren():
            if package.hasChildren():
                package_name = package.getElementName()
                package_code_element = CodeElement(codebase=self.codebase,
                        simple_name=package_name, fqn=package_name,
                        eclipse_handle=package.getHandleIdentifier(),
                        kind=self.package_kind, parser=JAVA_PARSER)
                package_code_element.save()
                packages.append((package, package_code_element))
        return packages

    def parse(self, progress_monitor=NullProgressMonitor()):
        '''Parses the codebase and creates CodeElement instances.

        :progress_monitor: A progress monitor to track the parsing progress.
        '''
        proot = self._get_package_root()
        packages = self._parse_packages(proot)
        progress_monitor.start('Parsing Java Project', len(packages))

        # Start workers:
        for _ in xrange(0, PARSER_WORKER):
            worker = CUWorker(self.queue, self.codebase, self.hierarchies,
                    self.gateway, progress_monitor)
            worker.start()

        start = time.time()
        for (package, package_code_element) in packages:
            gc.collect()  # for Py4J
            cunits = package.getCompilationUnits()
            unit_length = float(len(cunits))
            for cunit in cunits:
                ast_parser = self.ASTParser.newParser(self.JLS3)
                ast_parser.setResolveBindings(True)
                ast_parser.setSource(cunit)
                cu = ast_parser.createAST(None)
                winput = (cu, package_code_element, cunit.getElementName(),
                        1.0 / unit_length)
                self.queue.put(winput)

        for _ in xrange(0, PARSER_WORKER):
            self.queue.put(None)

        progress_monitor.info('Done parsing packages. Waiting for CUs.')
        self.queue.join()
        progress_monitor.done()
        self.gateway.close()
        print('Time: ' + str(time.time() - start))

        self.parse_hierarchy(progress_monitor)

    def parse_hierarchy(self, progress_monitor=NullProgressMonitor()):
        '''Builds the hierarchy of the parsed CodeElement instances.

        Must be called *after* parse.

        :param progress_monitor:
        '''
        queue = Queue()
        for hierarchy in self.hierarchies:
            queue.put(hierarchy)
#.........这里部分代码省略.........
开发者ID:bartdag,项目名称:recodoc2,代码行数:103,代码来源:java_code_parser.py

示例14: JavaSnippetParser

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import close [as 别名]
class JavaSnippetParser(object):

    HANDLE_SEPARATOR = ":"
    TYPE_KIND = "T"
    METHOD_KIND = "M"
    FIELD_KIND = "F"
    ANNOTATION_KIND = "A"
    ANNOTATION_PARAMETER_KIND = "P"
    ENUM_KIND = "E"
    ENUM_VALUE_KIND = "V"

    REQUEST_NAME = 'recodoc_request'

    def __init__(self, project, source):
        self.project = project
        self.source = source
        self._load()

    def _load(self):
        self.gateway = JavaGateway(start_callback_server=False)
        self.PPACoreUtil = \
                self.gateway.jvm.ca.mcgill.cs.swevo.ppa.util.PPACoreUtil
        self.class_kind = CodeElementKind.objects.get(kind='class')
        self.unknown_kind = CodeElementKind.objects.get(kind='unknown')
        self.method_kind = CodeElementKind.objects.get(kind='method')
        self.field_kind = CodeElementKind.objects.get(kind='field')
        self.enumeration_kind = CodeElementKind.objects.get(kind='enumeration')
        self.annotation_kind = CodeElementKind.objects.get(kind='annotation')

    def parse(self, progress_monitor=NullProgressMonitor()):
        options = self.gateway.jvm.ca.mcgill.cs.swevo.ppa.PPAOptions()
        mcodes = CodeSnippet.objects.filter(language='j').\
                filter(project=self.project).\
                filter(source=self.source)

        #mcodes = CodeSnippet.objects.filter(pk=122170)
        count = mcodes.count()
        progress_monitor.start('Parsing Code Snippets ({0})'
                .format(count), count)

        for mcode in mcodes:

            # Don't parse snippets that are already parsed.
            if mcode.single_code_references.count() > 0:
                progress_monitor.word('Skipped a parsed code snippet', 1)
                continue

            text = mcode.snippet_text
            if text != None and text != '':
                try:
                    cu = self._get_cu(text, options)
                    if cu != None:
                        visitor = self.gateway.jvm.ca.mcgill.cs.swevo.ppa.\
                                util.NameMapVisitor(True, True, True)
                        cu.accept(visitor)
                        self._process_name(
                                visitor.getBindings(),
                                visitor.getDeclarations(),
                                visitor.getNodes(),
                                mcode)
                except Exception:
                    logger.exception(
                            'Error with snippet: PK: {0}. Text:\n\n: {1}'
                            .format(mcode.pk, text))
                finally:
                    try:
                        self.PPACoreUtil.cleanUpAll(self.REQUEST_NAME)
                    except Exception:
                        print_exc()
            else:
                print('issue!')
            gc.collect()
            progress_monitor.work('Parsed a Code Snippet: pk={0}'
                    .format(mcode.pk), 1)

        progress_monitor.done()
        self.gateway.close()

    def _get_cu(self, text, options):
        try:
            if is_cu_body(text):
                cu = self.PPACoreUtil.getCU(text, options, self.REQUEST_NAME)
            elif is_class_body(text):
                cu = self.PPACoreUtil.getSnippet(text, options, True,
                        self.REQUEST_NAME)
            else:
                cu = self.PPACoreUtil.getSnippet(text, options, False,
                        self.REQUEST_NAME)
        except Exception:
            cu = None
            logger.exception('Error while processing cu for {0}'.format(text))
        return cu

    def _process_name(self, bindings, declarations, nodes, mcode):
        for i, binding in enumerate(bindings):
            declaration = declarations[i]
            parts = binding.split(self.HANDLE_SEPARATOR)
            kind = parts[0][2]
            kind_hint = None
            content = binding
#.........这里部分代码省略.........
开发者ID:bartdag,项目名称:recodoc2,代码行数:103,代码来源:java_snippet_parser.py


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