Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPype doesn't work inside thread?

I tested out a simple hello world line to test out JPype:

jpype.java.lang.System.out.println("hello world")

It works great inside the context of a "main" python program. However, inside the context of a running thread, I get the following response:

#
# 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
like image 591
saigafreak Avatar asked Jan 18 '23 11:01

saigafreak


1 Answers

citing from the JPype documentation:

Python Threads

For the most part, python threads based on OS level threads (i.e posix threads), will work without problem. The only thing to remember is to call jpype.attachThreadToJVM() in the thread body to make the JVM usable from that thread. For threads that you do not start yourself, you can call isThreadAttachedToJVM() to check.

HTH

like image 79
MartinStettner Avatar answered Jan 25 '23 07:01

MartinStettner