本文整理汇总了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)
示例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))
示例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()
示例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
示例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)
示例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()
)
示例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)
示例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