我测试了一个简单的hello world line来测试JPype:
jpype.java.lang.System.out.println(“hello world”)
它在“主要”python程序的上下文中运行良好。但是,在正在运行的线程的上下文中,我得到以下响应:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f5272aeb226, pid=7888, tid=139991902578432
#
# JRE version: 7.0_01-b08
# Java VM: Java HotSpot(TM) 64-Bit Server VM (21.1-b02 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [_jpype.so+0x33226] JPJavaEnv::FindClass(char const*)+0x36
#
# 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:
# /home/imedia/NTsvm/src/server/nlp/hs_err_pid7888.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
#
Aborted
答案 0 :(得分:8)
Python线程
在大多数情况下,基于操作系统级别线程(即posix线程)的python线程可以正常工作。唯一要记住的是在线程主体中调用
jpype.attachThreadToJVM()
以使JVM可以从该线程中使用。对于您自己没有开始的线程,您可以致电isThreadAttachedToJVM()
进行检查。
HTH