Please help help ..... for threading

S

silkenpy

Hi,
please help me to find a solution to run this program correctlly or tell me
my basic mistake.

import thread
import threading
import time
from jpype import *

def sleepFunction():
print"ya ali"

classpath = "-Djava.class.path=praat.jar"

startJVM(getDefaultJVMPath(),"-ea",classpath)

Formant=JPackage("praat").Formant
s=Formant("iia-001-000.Formant")
w=s.getF2_frequency()
print w
shutdownJVM()


for i in range(1):
thread.start_new_thread(sleepFunction, ())
time.sleep(1)
print "goodbye!"


The result is
ya ali
ya ali
Unhandled exception in thread started by <function sleepFunction at
0x00BFE370>
Traceback (most recent call last):
File
"C:\Downloads\_extracted\py_threading.zip.extracted\py_threading\sle.py",
line 19, in sleepFunction
startJVM(getDefaultJVMPath(),"-ea",classpath)
File "D:\Python25\Lib\site-packages\jpype\_core.py", line 43, in startJVM
_jpype.startup(jvm, tuple(args), True)
RuntimeError: Unable to start JVM at src/native/common/jp_env.cpp:54
Unhandled exception in thread started by <function sleepFunction at
0x00BFE370>
Traceback (most recent call last):
File
"C:\Downloads\_extracted\py_threading.zip.extracted\py_threading\sle.py",
line 19, in sleepFunction
startJVM(getDefaultJVMPath(),"-ea",classpath)
File "D:\Python25\Lib\site-packages\jpype\_core.py", line 43, in startJVM
_jpype.startup(jvm, tuple(args), True)
RuntimeError: Unknown Exception
goodbye!

Thanks a lot.
 
D

Dennis Lee Bieber

Hi,
please help me to find a solution to run this program correctlly or tell me
my basic mistake.

import thread
import threading

#1 Importing BOTH low-level thread and high-level threading...
suggest you just use threading.Thread and not the thread module itself.
import time
from jpype import *

def sleepFunction():
print"ya ali"

classpath = "-Djava.class.path=praat.jar"

startJVM(getDefaultJVMPath(),"-ea",classpath)

#2 -- possible; I've not used jpype but... a quick look at the HTML
documentation gave me the impression that you are supposed to start the
JVM outside of the thread (same for terminating it).

#3 -- possible; there was some sort of method for attaching a Python
thread to the JVM that you are NOT invoking.

http://jpype.sourceforge.net/doc/user-guide/userguide.html#threading
Formant=JPackage("praat").Formant
s=Formant("iia-001-000.Formant")
w=s.getF2_frequency()
print w
shutdownJVM()

#4; see #2 above, and section 10 of the documentation linked above.
for i in range(1):
thread.start_new_thread(sleepFunction, ())

As mentioned, recommend you stick to threading module...
time.sleep(1)

I wouldn't be surprised if it takes longer than a second just to
load the JVM <G>

--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top