本文整理匯總了Python中jpype.isJVMStarted方法的典型用法代碼示例。如果您正苦於以下問題:Python jpype.isJVMStarted方法的具體用法?Python jpype.isJVMStarted怎麽用?Python jpype.isJVMStarted使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jpype
的用法示例。
在下文中一共展示了jpype.isJVMStarted方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import jpype [as 別名]
# 或者: from jpype import isJVMStarted [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: _start_jvm
# 需要導入模塊: import jpype [as 別名]
# 或者: from jpype import isJVMStarted [as 別名]
def _start_jvm(self, minimum_heap_size, maximum_heap_size):
jvm_options = [
'-Xms{minimum_heap_size}'.format(minimum_heap_size=minimum_heap_size),
'-Xmx{maximum_heap_size}'.format(maximum_heap_size=maximum_heap_size),
'-Djava.class.path={classpath}'.format(
classpath=self._classpath)
]
if not jpype.isJVMStarted():
jpype.startJVM(
jpype.getDefaultJVMPath(),
*jvm_options
)
示例3: _init_jvm
# 需要導入模塊: import jpype [as 別名]
# 或者: from jpype import isJVMStarted [as 別名]
def _init_jvm():
if not jpype.isJVMStarted():
jars = []
for top, dirs, files in os.walk(imp.find_module("twkorean")[1] + "/data/lib"):
for nm in files:
jars.append(os.path.join(top, nm))
jpype.startJVM(jpype.getDefaultJVMPath(),
"-Djava.class.path=%s" % os.pathsep.join(jars))
示例4: _start_jvm
# 需要導入模塊: import jpype [as 別名]
# 或者: from jpype import isJVMStarted [as 別名]
def _start_jvm(self):
"""Start JAVA virtual machine if it is not running."""
jar_location = resource_filename(__name__, 'infodynamics.jar')
if not jp.isJVMStarted():
jp.startJVM(jp.getDefaultJVMPath(), '-ea', ('-Djava.class.path=' +
jar_location))
示例5: _start_jvm
# 需要導入模塊: import jpype [as 別名]
# 或者: from jpype import isJVMStarted [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 isJVMStarted [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: create_connection
# 需要導入模塊: import jpype [as 別名]
# 或者: from jpype import isJVMStarted [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