gpt4 book ai didi

java - 将jar文件添加到jpype会使java崩溃

转载 作者:行者123 更新时间:2023-12-02 00:03:04 26 4
gpt4 key购买 nike

我正在使用flask-appbuilder 来构建应用程序。为了提交表单来执行ddl,我在startJVM()时向jpype添加了一个jar文件,但是java总是崩溃。下面是我的代码:

import jaydebeapi
from flask import flash

def execute_ddl(dic):
def set_up_conn(dic):
conn = jaydebeapi.connect(jclassname=dic['jclass'],
url=dic['url'],
driver_args=[dic['driver_name'],
dic['driver_params']],
jars=dic['jars'])
curs = conn.cursor()
curs.execute(dic['ddl'])
output = curs.fetchall()
print(output)
curs.close()
conn.close()
try:
import jpype
if not jpype.isJVMStarted():
jvmPath = jpype.getDefaultJVMPath()
flash(str(jvmPath), 'info')
jpype.startJVM(jvmPath, "-ea", "-Djava.class.path=/lib/uber-hive-jdbc-1.2.1.jar")

if not jpype.isThreadAttachedToJVM():
jpype.attachThreadToJVM()
jpype.java.lang.Thread.currentThread().\
setContextClassLoader(jpype.java.lang.ClassLoader.getSystemClassLoader())
set_up_conn(dic)
# post process form
flash('{} is submitted!'.format(dic['ddl']), 'info')
except Exception as e:
flash(str(e), 'info')

这是崩溃错误,我尝试了“ulimit -c unlimited”但没有成功。

# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007fce15f978b9, pid=12, tid=0x00007fce0f7fe700
#
# JRE version: OpenJDK Runtime Environment (8.0_181-b13) (build 1.8.0_181-8u181-b13-2~deb9u1-b13)
# Java VM: OpenJDK 64-Bit Server VM (25.181-b13 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [_jpype.cpython-37m-x86_64-linux-gnu.so+0x3f8b9]
JPJavaEnv::NewLocalRef(_jobject*)+0x9
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# //hs_err_pid12.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp

最佳答案

我使用了多线程,这就是原因。

Jaydebeapi 使用 jpype 启动 JVM。您需要在线程主体中使用 jpype.attachThreadToJVM() 以使 JVM 可从该线程使用。您可以使用jpype.isThreadAttachedToJVM()来检查它是否已附加。

关于java - 将jar文件添加到jpype会使java崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54044923/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com