BodenmillerGroup / bbsnippets

This repository contains general examples, code snippets and guidelines.
https://bodenmillergroup.github.io/bbsnippets
0 stars 1 forks source link

Javabridge example: Can only run `write_ome_tiff` once #10

Closed votti closed 5 years ago

votti commented 5 years ago

Using the ometiff_javabridge example in a jupyter notebook with python 3.7, I get the following error message when trying to run the write_ome_tiff command twice without restarting the kernel:

Traceback (most recent call last):
  File "/home/vitoz/miniconda3/envs/javabridge/lib/python3.5/site-packages/javabridge/jutil.py", line 281, in start_thread
    env = vm.create(args)
  File "_javabridge.pyx", line 653, in _javabridge.JB_VM.create
RuntimeError: Failed to create Java VM. Return code = -1
Failed to create Java VM

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-7-c5ab184a83c3> in <module>()
      1 write_ome_tiff(fn_out, np.array(ac.get_img_stack_cyx(), dtype=np.float32), ac.origin,
----> 2                ac.channel_metals, channel_names=ac.channel_labels, pixel_type=bioformats.omexml.PT_FLOAT)

<ipython-input-1-409863700d3d> in write_ome_tiff(path, img, name, fluor_names, channel_names, pixel_type)
     24         omexml.image(0).Pixels.Channel(i).SamplesPerPixel = 1
     25         omexml.image(0).Pixels.Channel(i).node.set(FIELD_FLUOR, fluor_name)
---> 26     javabridge.start_vm(class_path=bioformats.JARS)
     27     try:
     28         env = javabridge.get_env()

~/miniconda3/envs/javabridge/lib/python3.5/site-packages/javabridge/jutil.py in start_vm(args, class_path, max_heap_size, run_headless)
    312     start_event.wait()
    313     if not _javabridge.get_vm().is_active():
--> 314         raise RuntimeError("Failed to start Java VM")
    315     attach()
    316 

RuntimeError: Failed to start Java VM

Any idea why this is?

jwindhager commented 5 years ago

Apparently, javabridge cannot launch two JVM instances for the same thread/process (?). As an ugly workaround, one could use multithreading/multiprocessing, but I think this should be reported/fixed on the javabridge end instead.