2011-10-22 167 views
4

我測試了一個簡單的Hello World線來測試JPype:JPype不能在線程內工作嗎?

jpype.java.lang.System.out.println( 「世界你好」)

它的一個「主要的上下文中的偉大工程「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 

回答

8

JPype documentation理由:

Python的線程

在大多數情況下,基於OS蟒蛇線程高級線程(即posix線程)將毫無問題地工作。唯一要記住的是在線程體中調用jpype.attachThreadToJVM()以使JVM可以在該線程中使用。對於自己無法啓動的線程,可以致電isThreadAttachedToJVM()進行檢查。

HTH