當前位置: 首頁>>代碼示例>>Python>>正文


Python jpype.isThreadAttachedToJVM方法代碼示例

本文整理匯總了Python中jpype.isThreadAttachedToJVM方法的典型用法代碼示例。如果您正苦於以下問題:Python jpype.isThreadAttachedToJVM方法的具體用法?Python jpype.isThreadAttachedToJVM怎麽用?Python jpype.isThreadAttachedToJVM使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在jpype的用法示例。


在下文中一共展示了jpype.isThreadAttachedToJVM方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import jpype [as 別名]
# 或者: from jpype import isThreadAttachedToJVM [as 別名]
def __init__(
        self,
        jars=None,
        jvm_started=False,
        mark_time_ranges=False,
        include_range=False,
        jvm_flags=None,
        language="english",
    ):
        """Initializes SUTime.
        """
        self.jars = jars if jars is not None else []
        self._check_language_model_dependency(language.lower())

        if not jvm_started and not jpype.isJVMStarted():
            self._start_jvm(jvm_flags)

        if not jpype.isThreadAttachedToJVM():
            jpype.attachThreadToJVM()
        wrapper = jpype.JClass("edu.stanford.nlp.python.SUTimeWrapper")
        self._sutime = wrapper(mark_time_ranges, include_range, language) 
開發者ID:FraBle,項目名稱:python-sutime,代碼行數:23,代碼來源:sutime.py

示例2: parse

# 需要導入模塊: import jpype [as 別名]
# 或者: from jpype import isThreadAttachedToJVM [as 別名]
def parse(self, input_str, reference_date=""):
        """Parses datetime information out of string input.

        It invokes the SUTimeWrapper.annotate() function in Java.

        Args:
            input_str: The input as string that has to be parsed.
            reference_date: Optional reference data for SUTime.

        Returns:
            A list of dicts with the result from the SUTimeWrapper.annotate()
                call.
        """
        if not jpype.isThreadAttachedToJVM():
            jpype.attachThreadToJVM()
        if reference_date:
            return json.loads(self._sutime.annotate(input_str, reference_date))
        return json.loads(self._sutime.annotate(input_str)) 
開發者ID:FraBle,項目名稱:python-sutime,代碼行數:20,代碼來源:sutime.py

示例3: __init__

# 需要導入模塊: import jpype [as 別名]
# 或者: from jpype import isThreadAttachedToJVM [as 別名]
def __init__(self,
                 jvm_started=False,
                 parse_datetime=False,
                 minimum_heap_size='128m',
                 maximum_heap_size='2048m'):
        """Initializes Duckling.
        """

        self.parse_datetime = parse_datetime
        self._is_loaded = False
        self._lock = threading.Lock()

        if not jvm_started:
            self._classpath = self._create_classpath()
            self._start_jvm(minimum_heap_size, maximum_heap_size)

        try:
            # make it thread-safe
            if threading.activeCount() > 1:
                if not jpype.isThreadAttachedToJVM():
                    jpype.attachThreadToJVM()
            self._lock.acquire()

            self.clojure = jpype.JClass('clojure.java.api.Clojure')
            # require the duckling Clojure lib
            require = self.clojure.var("clojure.core", "require")
            require.invoke(self.clojure.read("duckling.core"))
        finally:
            self._lock.release() 
開發者ID:FraBle,項目名稱:python-duckling,代碼行數:31,代碼來源:duckling.py

示例4: attach_thread_to_jvm

# 需要導入模塊: import jpype [as 別名]
# 或者: from jpype import isThreadAttachedToJVM [as 別名]
def attach_thread_to_jvm(wrapped):
    @functools.wraps(wrapped)
    def _wrapper(*args, **kwargs):
        import jpype

        if not jpype.isThreadAttachedToJVM():
            jpype.attachThreadToJVM()
        return wrapped(*args, **kwargs)

    return _wrapper 
開發者ID:laughingman7743,項目名稱:PyAthenaJDBC,代碼行數:12,代碼來源:util.py

示例5: _start_jvm

# 需要導入模塊: import jpype [as 別名]
# 或者: from jpype import isThreadAttachedToJVM [as 別名]
def _start_jvm(cls, jvm_path, jvm_options, driver_path, log4j_conf):
        if jvm_path is None:
            jvm_path = jpype.get_default_jvm_path()
        if driver_path is None:
            driver_path = os.path.join(cls._BASE_PATH, ATHENA_JAR)
        if log4j_conf is None:
            log4j_conf = os.path.join(cls._BASE_PATH, LOG4J_PROPERTIES)
        if not jpype.isJVMStarted():
            _logger.debug("JVM path: %s", jvm_path)
            args = [
                "-server",
                "-Djava.class.path={0}".format(driver_path),
                "-Dlog4j.configuration=file:{0}".format(log4j_conf),
            ]
            if jvm_options:
                args.extend(jvm_options)
            _logger.debug("JVM args: %s", args)
            if jpype.__version__.startswith("0.6"):
                jpype.startJVM(jvm_path, *args)
            else:
                jpype.startJVM(
                    jvm_path, *args, ignoreUnrecognized=True, convertStrings=True
                )
            cls.class_loader = (
                jpype.java.lang.Thread.currentThread().getContextClassLoader()
            )
        if not jpype.isThreadAttachedToJVM():
            jpype.attachThreadToJVM()
            if not cls.class_loader:
                cls.class_loader = (
                    jpype.java.lang.Thread.currentThread().getContextClassLoader()
                )
            class_loader = jpype.java.net.URLClassLoader.newInstance(
                [jpype.java.net.URL("jar:file:{0}!/".format(driver_path))],
                cls.class_loader,
            )
            jpype.java.lang.Thread.currentThread().setContextClassLoader(class_loader) 
開發者ID:laughingman7743,項目名稱:PyAthenaJDBC,代碼行數:39,代碼來源:connection.py

示例6: attach_thread_to_jvm

# 需要導入模塊: import jpype [as 別名]
# 或者: from jpype import isThreadAttachedToJVM [as 別名]
def attach_thread_to_jvm() -> None:
    "https://github.com/baztian/jaydebeapi/issues/14#issuecomment-261489331"

    import jpype

    if jpype.isJVMStarted() and not jpype.isThreadAttachedToJVM():
        jpype.attachThreadToJVM()
        jpype.java.lang.Thread.currentThread().setContextClassLoader(
            jpype.java.lang.ClassLoader.getSystemClassLoader()
        ) 
開發者ID:koxudaxi,項目名稱:local-data-api,代碼行數:12,代碼來源:__init__.py

示例7: parse

# 需要導入模塊: import jpype [as 別名]
# 或者: from jpype import isThreadAttachedToJVM [as 別名]
def parse(self, input_str, language=Language.ENGLISH, dim_filter=None, reference_time=''):
        """Parses datetime information out of string input.

        It invokes the Duckling.parse() function in Clojure.
        A language can be specified, default is English.

        Args:
            input_str: The input as string that has to be parsed.
            language: Optional parameter to specify language,
                e.g. Duckling.ENGLISH or supported ISO 639-1 Code (e.g. "en")
            dim_filter: Optional parameter to specify a single filter or
                list of filters for dimensions in Duckling.
            reference_time: Optional reference time for Duckling.

        Returns:
            A list of dicts with the result from the Duckling.parse() call.

        Raises:
            RuntimeError: An error occurres when Duckling model is not loaded
                via load().
        """
        if self._is_loaded is False:
            raise RuntimeError(
                'Please load the model first by calling load()')
        if threading.activeCount() > 1:
            if not jpype.isThreadAttachedToJVM():
                jpype.attachThreadToJVM()
        language = Language.convert_to_duckling_language_id(language)
        duckling_parse = self.clojure.var("duckling.core", "parse")
        duckling_time = self.clojure.var("duckling.time.obj", "t")
        clojure_hashmap = self.clojure.var("clojure.core", "hash-map")

        filter_str = '[]'
        if isinstance(dim_filter, string_types):
            filter_str = '[:{filter}]'.format(filter=dim_filter)
        elif isinstance(dim_filter, list):
            filter_str = '[{filter}]'.format(filter=' :'.join(dim_filter))
        if reference_time:
            duckling_result = duckling_parse.invoke(
                language,
                input_str,
                self.clojure.read(filter_str),
                clojure_hashmap.invoke(
                    self.clojure.read(':reference-time'),
                    duckling_time.invoke(
                        *self._parse_reference_time(reference_time))
                )
            )
        else:
            duckling_result = duckling_parse.invoke(
                language, input_str, self.clojure.read(filter_str))
        return self._parse_result(duckling_result) 
開發者ID:FraBle,項目名稱:python-duckling,代碼行數:54,代碼來源:duckling.py

示例8: create_connection

# 需要導入模塊: import jpype [as 別名]
# 或者: from jpype import isThreadAttachedToJVM [as 別名]
def create_connection(self):
        service_check_tags = ['server:%s' % self._server]
        service_check_tags.extend(self._tags)

        try:
            # Check if the instantclient is available
            cx_Oracle.clientversion()
        except cx_Oracle.DatabaseError as e:
            # Fallback to JDBC
            use_oracle_client = False
            self.log.debug('Oracle instant client unavailable, falling back to JDBC: %s', e)
            connect_string = self.JDBC_CONNECT_STRING.format(self._server, self._service)
        else:
            use_oracle_client = True
            self.log.debug('Running cx_Oracle version %s', cx_Oracle.version)
            connect_string = self.CX_CONNECT_STRING.format(self._user, self._password, self._server, self._service)

        try:
            if use_oracle_client:
                connection = cx_Oracle.connect(connect_string)
            elif JDBC_IMPORT_ERROR:
                self.log.error(
                    "Oracle client is unavailable and the integration is unable to import JDBC libraries. You may not "
                    "have the Microsoft Visual C++ Runtime 2015 installed on your system. Please double check your "
                    "installation and refer to the Datadog documentation for more information."
                )
                raise JDBC_IMPORT_ERROR
            else:
                try:
                    if jpype.isJVMStarted() and not jpype.isThreadAttachedToJVM():
                        jpype.attachThreadToJVM()
                        jpype.java.lang.Thread.currentThread().setContextClassLoader(
                            jpype.java.lang.ClassLoader.getSystemClassLoader()
                        )
                    connection = jdb.connect(
                        self.ORACLE_DRIVER_CLASS, connect_string, [self._user, self._password], self._jdbc_driver
                    )
                except Exception as e:
                    if "Class {} not found".format(self.ORACLE_DRIVER_CLASS) in str(e):
                        msg = """Cannot run the Oracle check until either the Oracle instant client or the JDBC Driver
                        is available.
                        For the Oracle instant client, see:
                        http://www.oracle.com/technetwork/database/features/instant-client/index.html
                        You will also need to ensure the `LD_LIBRARY_PATH` is also updated so the libs are reachable.

                        For the JDBC Driver, see:
                        http://www.oracle.com/technetwork/database/application-development/jdbc/downloads/index.html
                        You will also need to ensure the jar is either listed in your $CLASSPATH or in the yaml
                        configuration file of the check.
                        """
                        self.log.error(msg)
                    raise

            self.log.debug("Connected to Oracle DB")
            self.service_check(self.SERVICE_CHECK_NAME, AgentCheck.OK, tags=service_check_tags)
        except Exception as e:
            self.service_check(self.SERVICE_CHECK_NAME, AgentCheck.CRITICAL, tags=service_check_tags)
            self.log.error(e)
            raise
        self._connection = connection 
開發者ID:DataDog,項目名稱:integrations-core,代碼行數:62,代碼來源:oracle.py


注:本文中的jpype.isThreadAttachedToJVM方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。