Stopping & Restarting the JVM

135 views
Skip to first unread message

Andreas DerMaster

unread,
Mar 23, 2021, 12:10:13 PM3/23/21
to python-weka-wrapper
Hello everyone,
at the moment I am re-evaluating a few papers in Python. As a few papers used Weka classifiers, I opted to use the convenient Python wrapper. 
The requirements and scenarios vary a bit, so I would e.g. use larger heaps for one paper, other options like package support for others and change the JVM startup parameters.
However, even a simple script like:

from weka.core import jvm
jvm.start()
jvm.stop()
jvm.start()  # fails here
jvm.stop()

fails on the restart of the JVM with:

DEBUG:weka.core.jvm:Adding bundled jars
DEBUG:weka.core.jvm:Classpath=['/home/user/.local/lib/python3.8/site-packages/javabridge/jars/rhino-1.7R4.jar', '/home/user/.local/lib/python3.8/site-packages/javabridge/jars/runnablequeue.jar', '/home/user/.local/lib/python3.8/site-packages/javabridge/jars/cpython.jar', '/home/user/.local/lib/python3.8/site-packages/weka/lib/weka.jar', '/home/user/.local/lib/python3.8/site-packages/weka/lib/python-weka-wrapper.jar', '/home/user/.local/lib/python3.8/site-packages/weka/lib/weka.jar', '/home/user/.local/lib/python3.8/site-packages/weka/lib/python-weka-wrapper.jar']
DEBUG:weka.core.jvm:MaxHeapSize=default
DEBUG:weka.core.jvm:Package support disabled
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.8/site-packages/javabridge/jutil.py", line 286, in start_thread
    env = vm.create(args)
  File "_javabridge.pyx", line 654, in _javabridge.JB_VM.create
RuntimeError: Failed to create Java VM. Return code = -1
ERROR:javabridge.jutil:Failed to create Java VM
Traceback (most recent call last):
  File "/home/user/example/test.py", line 4, in <module>
    jvm.start()
  File "/home/user/.local/lib/python3.8/site-packages/weka/core/jvm.py", line 129, in start
    javabridge.start_vm(args=args, run_headless=True, max_heap_size=max_heap_size)
  File "/home/user/.local/lib/python3.8/site-packages/javabridge/jutil.py", line 319, in start_vm
    raise RuntimeError("Failed to start Java VM")
RuntimeError: Failed to start Java VM
Process finished with exit code 1

I would like to know: Is it a problem with my installation? Or an asynchronous shutdown of the JVM in the background? Or a problem with the javabridge Package? Or some kind of another problem?

A workaround on my side is simply reusing the same JVM for all evaluations, or splitting the executions across multiple Python Executions. However, stopping and restarting within Python would be really convenient. :)

Thanks in advance for any hints. It is not a necessary functionality for me, but the jvm.stop() method did not work as I expected it to work.

Greetings, 
Andreas

TLDR: Is it possible to execute jvm.start() after stopping a prior JVM with jvm.stop()?



Peter Reutemann

unread,
Mar 23, 2021, 3:25:19 PM3/23/21
to python-weka-wrapper
> TLDR: Is it possible to execute jvm.start() after stopping a prior JVM with jvm.stop()?

Unfortunately, not. That is one of the drawbacks of the javabridge
library that pww3 uses.

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 577-5304
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/

Andreas DerMaster

unread,
Mar 23, 2021, 4:04:05 PM3/23/21
to python-weka-wrapper
Alright. 
Thank you very much for the quick answers!

Best,
Andreas

Reply all
Reply to author
Forward
0 new messages