Script hangs on MacOS with external drive

Based off an example batch Jython macro, I have created the below script, which works beautifully for my purposes. What is weird is that it hangs on macOS Catalina 10.15.1 when analyzing a folder on an external drive. It gets through a few images and then ImageJ silently quits. It works great on ALL images when the images are on the internal HD. I have tested with the same images in both locations.

Seems like it might be an issue with macOS and possible permissions?

import os, sys  
from ij.io import FileSaver  
from ij import IJ, ImagePlus, ImageStack, WindowManager
from ij.plugin import RGBStackMerge
from ij.process import ImageConverter
  
sourceDir = "/Users/myname/Desktop/testimages" 
targetDir = "/Users/nyame/Desktop/output"
#fails if targetdir is on an external drive, location of souceDir doesn't seem to matter

# A function that takes an stack and adjust color and contrast and then makes RGB 
def normalizeContrast(imp):  
  stack1 = imp.getImageStack()
  print imp.getTitle()
  print stack1.getSize()
  dapi_info = stack1.getProcessor(1)
  dapi_imp = IJ.createImage("DAPI", 284, 154,1,8)
  dapi_imp.setProcessor(dapi_info)
  IJ.run(dapi_imp, "Blue", "") 
  fitc_info = stack1.getProcessor(2)
  fitc_imp = IJ.createImage("FITC", 284, 154,1,8)
  fitc_imp.setProcessor(fitc_info)
  IJ.run(fitc_imp, "Green", "") 
  IJ.run(fitc_imp, "Enhance Contrast...", "saturated=0.3 process_all")
  final = RGBStackMerge.mergeChannels([dapi_imp,fitc_imp], False)
  ImageConverter(final).convertToRGB()
  copy_ip = final.getProcessor().duplicate()  
  # Return as new image  
  return ImagePlus(imp.getTitle(), copy_ip)  
  
  
# A function that takes a file path, attempts to load it as an image,  
# normalizes it, and saves it in a different directory  
def loadProcessAndSave(sourcepath, fn):  
  try:  
    imp = IJ.openImage(sourcepath)  
    norm_imp = fn(imp) # invoke function 'fn', in this case 'normalizeContrast'  
    targetpath = os.path.join(targetDir, os.path.basename(sourcepath))  
    if not targetpath.endswith(".png"):  
      targetpath += ".png"  
    FileSaver(norm_imp).saveAsPng(targetpath)  
  except:  
    print "Could not load or process file:", sourcepath  
    print sys.exc_info()  
  
  
# Stategy #1: nested directories with os.listdir and os.path.isdir  
def processDirectory(theDir, fn):  
  """ For every file in theDir, check if it is a directory, if so, invoke recursively. 
      If not a directory, invoke 'loadProcessAndSave' on it. """  
  for filename in os.listdir(theDir):  
    path = os.path.join(theDir, filename)  
    if os.path.isdir(path):  
      # Recursive call  
      processDirectory(path, fn)  
    else:  
      loadProcessAndSave(path, fn)  
  
# Launch strategy 1:  
processDirectory(sourceDir, normalizeContrast)

That is indeed weird!

Is it a hang—the program stops working and becomes unresponsive? Or a crash—the program terminates?

Depending on which, one of these Troubleshooting pages may be helpful to diagnose:

Either way, the first step is to launch ImageJ from the console.

I should clarify that it is FIJI that I am using, and that it doesn’t quit or hang, per se. I have monitored Activity Monitor, and the CPU usage of ImageJ increase appropriately for the first few images. After this, the program doesn’t quit, the GUI doesn’t change, but the process usage goes to 0-10% (baseline) but without any feedback from the GUI or the script output. FIJI works normally, it’s almost as if the script is silently killed? It’s what made me think of the macOS Catalina permissions idea, but that’s just my hypothesis. I will launch from the console and look at the debug.

@ctrueden, two updates.

  1. I have the outputs from the debug mode of FIJI when running the script, but I can’t say that they mean much to me :slight_smile: Would it be helpful to post here?
  2. The script works when the output is directed to a directory on the internal drive (reading images from the external volume), but fails in the opposite direction (read from internal drive and write to external volume).

Yes, seeing the debug log will for sure be useful. (You can put it in a Hide Details block, accessible via the :gear: (gear) icon of the forum editor, if you think it bloats this topic too much.)

So you’re saying, it fails when targetDir is on the external drive (as opposed to the comment in your original code pointing to sourceDir)?

Can you try to reduce the issue to FileSaver.saveAsPng(), with some images generated e.g. by IJ.createImage()?

1 Like

Definitely! In particular, the full thread dump can be very illustrative. If you enclose it in code fences (three backtick characters before and after) then it will render in a scrollable box with fixed width font.

That is correct, I will update the original code to reflect this.

Thread Dump
Full thread dump OpenJDK 64-Bit Server VM (25.202-b08 mixed mode):

"Script Editor Run :: Tue Dec 10 13:34:27 MST 2019" #46 prio=5 os_prio=31 tid=0x00007fa434520000 nid=0x1036f waiting on condition [0x0000700004061000]
   java.lang.Thread.State: WAITING (parking)
	at sun.misc.Unsafe.park(Native Method)
	- parking to wait for  <0x000000071cb10840> (a java.util.concurrent.FutureTask)
	at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
	at java.util.concurrent.FutureTask.awaitDone(FutureTask.java:429)
	at java.util.concurrent.FutureTask.get(FutureTask.java:191)
	at org.scijava.ui.swing.script.TextEditor.evalScript(TextEditor.java:2713)
	at org.scijava.ui.swing.script.TextEditor.access$600(TextEditor.java:177)
	at org.scijava.ui.swing.script.TextEditor$5.execute(TextEditor.java:2189)
	at org.scijava.ui.swing.script.TextEditor$Executer$1.run(TextEditor.java:1964)

"pool-6-thread-1" #45 prio=5 os_prio=31 tid=0x00007fa433530000 nid=0x1655f waiting on condition [0x0000700003f5e000]
   java.lang.Thread.State: TIMED_WAITING (parking)
	at sun.misc.Unsafe.park(Native Method)
	- parking to wait for  <0x000000071cabb7d8> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
	at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
	at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
	at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
	at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

"pool-5-thread-1" #44 prio=5 os_prio=31 tid=0x00007fa42fe82000 nid=0xfa2f waiting on condition [0x0000700003b52000]
   java.lang.Thread.State: TIMED_WAITING (parking)
	at sun.misc.Unsafe.park(Native Method)
	- parking to wait for  <0x000000071cabb1c0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
	at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
	at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
	at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
	at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

"Thread-5" #30 prio=5 os_prio=31 tid=0x00007fa42c64d000 nid=0x11a7f waiting on condition [0x0000700003e5b000]
   java.lang.Thread.State: WAITING (parking)
	at sun.misc.Unsafe.park(Native Method)
	- parking to wait for  <0x0000000571576c70> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
	at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
	at java.util.concurrent.LinkedBlockingDeque.takeFirst(LinkedBlockingDeque.java:492)
	at java.util.concurrent.LinkedBlockingDeque.take(LinkedBlockingDeque.java:680)
	at sun.nio.fs.AbstractWatchService.take(AbstractWatchService.java:118)
	at org.scijava.ui.swing.script.FileSystemTree$DirectoryWatcher.run(FileSystemTree.java:480)

"DestroyJavaVM" #28 prio=5 os_prio=31 tid=0x00007fa4313e0800 nid=0x1107 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"SciJava-76e5ea52-Thread-1" #27 prio=5 os_prio=31 tid=0x00007fa430f1c000 nid=0xdc0b waiting on condition [0x0000700003d58000]
   java.lang.Thread.State: TIMED_WAITING (parking)
	at sun.misc.Unsafe.park(Native Method)
	- parking to wait for  <0x000000056f643490> (a java.util.concurrent.SynchronousQueue$TransferStack)
	at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
	at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:460)
	at java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:362)
	at java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:941)
	at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1073)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

"TimerQueue" #26 daemon prio=5 os_prio=31 tid=0x00007fa42bc23000 nid=0xd51b waiting on condition [0x0000700003c55000]
   java.lang.Thread.State: WAITING (parking)
	at sun.misc.Unsafe.park(Native Method)
	- parking to wait for  <0x0000000571b437b0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
	at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
	at java.util.concurrent.DelayQueue.take(DelayQueue.java:211)
	at javax.swing.TimerQueue.run(TimerQueue.java:174)
	at java.lang.Thread.run(Thread.java:748)

"AWT-EventQueue-0" #21 prio=6 os_prio=31 tid=0x00007fa42fc52800 nid=0x11eef waiting on condition [0x0000700003a4f000]
   java.lang.Thread.State: WAITING (parking)
	at sun.misc.Unsafe.park(Native Method)
	- parking to wait for  <0x000000056f62c2c0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
	at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
	at java.awt.EventQueue.getNextEvent(EventQueue.java:554)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:187)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

"AWT-Shutdown" #22 prio=5 os_prio=31 tid=0x00007fa42fdd5800 nid=0x11c1b in Object.wait() [0x0000700003746000]
   java.lang.Thread.State: WAITING (on object monitor)
	at java.lang.Object.wait(Native Method)
	at java.lang.Object.wait(Object.java:502)
	at sun.awt.AWTAutoShutdown.run(AWTAutoShutdown.java:295)
	- locked <0x000000056f6249b0> (a java.lang.Object)
	at java.lang.Thread.run(Thread.java:748)

"Java2D Disposer" #17 daemon prio=10 os_prio=31 tid=0x00007fa431b02000 nid=0x11f13 in Object.wait() [0x000070000394c000]
   java.lang.Thread.State: WAITING (on object monitor)
	at java.lang.Object.wait(Native Method)
	at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
	- locked <0x00000005700588b0> (a java.lang.ref.ReferenceQueue$Lock)
	at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165)
	at sun.java2d.Disposer.run(Disposer.java:148)
	at java.lang.Thread.run(Thread.java:748)

"Java2D Queue Flusher" #15 daemon prio=10 os_prio=31 tid=0x00007fa42fa5b800 nid=0x930b in Object.wait() [0x000070000353d000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
	at java.lang.Object.wait(Native Method)
	at sun.java2d.opengl.OGLRenderQueue$QueueFlusher.run(OGLRenderQueue.java:203)
	- locked <0x0000000570081cd8> (a sun.java2d.opengl.OGLRenderQueue$QueueFlusher)

"Run$_SciJava-76e5ea52-Thread-0" #14 prio=5 os_prio=31 tid=0x00007fa42bccb800 nid=0xbf07 runnable [0x0000700003847000]
   java.lang.Thread.State: RUNNABLE
	at java.io.RandomAccessFile.writeBytes(Native Method)
	at java.io.RandomAccessFile.write(RandomAccessFile.java:525)
	at javax.imageio.stream.FileImageOutputStream.write(FileImageOutputStream.java:124)
	at com.sun.imageio.plugins.png.IDATOutputStream.deflate(PNGImageWriter.java:232)
	at com.sun.imageio.plugins.png.IDATOutputStream.write(PNGImageWriter.java:215)
	at com.sun.imageio.plugins.png.PNGImageWriter.encodePass(PNGImageWriter.java:908)
	at com.sun.imageio.plugins.png.PNGImageWriter.write_IDAT(PNGImageWriter.java:942)
	at com.sun.imageio.plugins.png.PNGImageWriter.write(PNGImageWriter.java:1158)
	at javax.imageio.ImageWriter.write(ImageWriter.java:615)
	at javax.imageio.ImageIO.doWrite(ImageIO.java:1612)
	at javax.imageio.ImageIO.write(ImageIO.java:1536)
	at ij.plugin.PNG_Writer.writeImage(PNG_Writer.java:53)
	at ij.plugin.PNG_Writer.run(PNG_Writer.java:33)
	at ij.IJ.runPlugIn(IJ.java:199)
	at ij.IJ.runPlugIn(IJ.java:173)
	at ij.io.FileSaver.saveAsPng(FileSaver.java:439)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:206)
	at org.python.core.PyObject.__call__(PyObject.java:497)
	at org.python.core.PyObject.__call__(PyObject.java:501)
	at org.python.core.PyMethod.__call__(PyMethod.java:141)
	at org.python.pycode._pyx2.loadProcessAndSave$2(New_.py:54)
	at org.python.pycode._pyx2.call_function(New_.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:171)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:154)
	at org.python.core.PyFunction.__call__(PyFunction.java:423)
	at org.python.pycode._pyx2.processDirectory$3(New_.py:61)
	at org.python.pycode._pyx2.call_function(New_.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:171)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:154)
	at org.python.core.PyFunction.__call__(PyFunction.java:423)
	at org.python.pycode._pyx2.f$0(New_.py:70)
	at org.python.pycode._pyx2.call_function(New_.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:171)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1614)
	at org.python.core.__builtin__.eval(__builtin__.java:497)
	at org.python.core.__builtin__.eval(__builtin__.java:501)
	at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
	at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:228)
	at org.scijava.thread.DefaultThreadService$$Lambda$126/472695518.call(Unknown Source)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

"AppKit Thread" #11 daemon prio=5 os_prio=31 tid=0x00007fa42e083000 nid=0x307 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Timer-0" #9 daemon prio=5 os_prio=31 tid=0x00007fa42c1cf800 nid=0x3703 in Object.wait() [0x00007000032b1000]
   java.lang.Thread.State: WAITING (on object monitor)
	at java.lang.Object.wait(Native Method)
	at java.lang.Object.wait(Object.java:502)
	at java.util.TimerThread.mainLoop(Timer.java:526)
	- locked <0x000000056f624ce0> (a java.util.TaskQueue)
	at java.util.TimerThread.run(Timer.java:505)

"Service Thread" #8 daemon prio=9 os_prio=31 tid=0x00007fa42d018000 nid=0x4503 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C1 CompilerThread2" #7 daemon prio=9 os_prio=31 tid=0x00007fa42c80f000 nid=0x3603 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread1" #6 daemon prio=9 os_prio=31 tid=0x00007fa42b817000 nid=0x3503 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" #5 daemon prio=9 os_prio=31 tid=0x00007fa42b80a000 nid=0x4803 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" #4 daemon prio=9 os_prio=31 tid=0x00007fa42b809800 nid=0x4903 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Finalizer" #3 daemon prio=8 os_prio=31 tid=0x00007fa42d015000 nid=0x5403 in Object.wait() [0x0000700002a96000]
   java.lang.Thread.State: WAITING (on object monitor)
	at java.lang.Object.wait(Native Method)
	at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
	- locked <0x000000056f625510> (a java.lang.ref.ReferenceQueue$Lock)
	at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165)
	at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:216)

"Reference Handler" #2 daemon prio=10 os_prio=31 tid=0x00007fa42c801000 nid=0x2d03 in Object.wait() [0x0000700002993000]
   java.lang.Thread.State: WAITING (on object monitor)
	at java.lang.Object.wait(Native Method)
	at java.lang.Object.wait(Object.java:502)
	at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
	- locked <0x000000056f62c808> (a java.lang.ref.Reference$Lock)
	at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)

"VM Thread" os_prio=31 tid=0x00007fa42d00e800 nid=0x2b03 runnable

"GC task thread#0 (ParallelGC)" os_prio=31 tid=0x00007fa42d006000 nid=0x2007 runnable

"GC task thread#1 (ParallelGC)" os_prio=31 tid=0x00007fa42b803800 nid=0x1b03 runnable

"GC task thread#2 (ParallelGC)" os_prio=31 tid=0x00007fa42b804000 nid=0x1e03 runnable

"GC task thread#3 (ParallelGC)" os_prio=31 tid=0x00007fa42b804800 nid=0x1d03 runnable

"VM Periodic Task Thread" os_prio=31 tid=0x00007fa42d016800 nid=0x4303 waiting on condition

JNI global references: 5179

Heap
 PSYoungGen      total 542720K, used 308384K [0x00000006fa780000, 0x000000071f500000, 0x00000007c0000000)
  eden space 499200K, 53% used [0x00000006fa780000,0x000000070aa29470,0x0000000718f00000)
  from space 43520K, 99% used [0x000000071ca80000,0x000000071f4fec68,0x000000071f500000)
  to   space 52224K, 0% used [0x0000000718f00000,0x0000000718f00000,0x000000071c200000)
 ParOldGen       total 248320K, used 106539K [0x000000056f600000, 0x000000057e880000, 0x00000006fa780000)
  object space 248320K, 42% used [0x000000056f600000,0x0000000575e0ad60,0x000000057e880000)
 Metaspace       used 76913K, capacity 80549K, committed 80728K, reserved 1116160K
  class space    used 13489K, capacity 14111K, committed 14208K, reserved 1048576K


Thanks, @Chris4! Here is the interesting part of the thread dump:

"Run$_SciJava-76e5ea52-Thread-0" #14 prio=5 os_prio=31 tid=0x00007fa42bccb800 nid=0xbf07 runnable [0x0000700003847000]
   java.lang.Thread.State: RUNNABLE
	at java.io.RandomAccessFile.writeBytes(Native Method)
	at java.io.RandomAccessFile.write(RandomAccessFile.java:525)
	at javax.imageio.stream.FileImageOutputStream.write(FileImageOutputStream.java:124)
	at com.sun.imageio.plugins.png.IDATOutputStream.deflate(PNGImageWriter.java:232)
	at com.sun.imageio.plugins.png.IDATOutputStream.write(PNGImageWriter.java:215)
	at com.sun.imageio.plugins.png.PNGImageWriter.encodePass(PNGImageWriter.java:908)
	at com.sun.imageio.plugins.png.PNGImageWriter.write_IDAT(PNGImageWriter.java:942)
	at com.sun.imageio.plugins.png.PNGImageWriter.write(PNGImageWriter.java:1158)
	at javax.imageio.ImageWriter.write(ImageWriter.java:615)
	at javax.imageio.ImageIO.doWrite(ImageIO.java:1612)
	at javax.imageio.ImageIO.write(ImageIO.java:1536)
	at ij.plugin.PNG_Writer.writeImage(PNG_Writer.java:53)
	at ij.plugin.PNG_Writer.run(PNG_Writer.java:33)
	at ij.IJ.runPlugIn(IJ.java:199)
	at ij.IJ.runPlugIn(IJ.java:173)
	at ij.io.FileSaver.saveAsPng(FileSaver.java:439)

What this says is (reading from bottom to top): there is an active ImageJ operation running that is saving a PNG file, using the ImageJ1 PNG_Writer logic, which leans on Java’s built-in PNG support (ImageIO), and bytes are currently being written by that operation.

The fact that the operation stalls there suggests to me bad sectors on your external drive, which are being hit by the write. OSes are known to stall for long periods of time in that situation. Also possible is a connectivity issue, where the external drive’s connection to your machine is somehow intermittent. In my experience, sometimes active operations will fail fast with I/O errors in these scenarios, and sometimes they just hang.

In any case, I’d suggest you run some health checks on your drive to see if there are problems that can be repaired.

1 Like

@ctrueden Thanks for your response. I did some checks on the external drive and everything seems to work out well. Upon more testing, If I simply replace the FileSaver(norm_imp).saveAsPng(targetpath) with FileSaver(norm_imp).saveAsJpeg(targetpath) the script does not “silently end”.

For now, exporting to Jpeg is fine for me, but perhaps there is something else?

1 Like