Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.python
Please help help ..... for threading
silkenpy
2/15/2008 1:01:00 AM
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.
--
View this message in context:
http://www.nabble.com/Please-help-help-.....-for-threading-tp15492998p154...
Sent from the Python - python-list mailing list archive at Nabble.com.
1 Answer
Dennis Lee Bieber
2/15/2008 6:27:00 AM
0
On Thu, 14 Feb 2008 17:01:14 -0800 (PST), silkenpy
<ali_292000@yahoo.com> declaimed the following in comp.lang.python:
>
> 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...
>
> 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
wlfraed@ix.netcom.com wulfraed@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-asst@bestiaria.com)
HTTP://www.bestiaria.com/
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Please help help ..... for threading
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password