diff --git a/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/PytorchJavaCPPInterface.java b/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/PytorchJavaCPPInterface.java index f0dafca..2b33825 100644 --- a/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/PytorchJavaCPPInterface.java +++ b/src/main/java/io/bioimage/modelrunner/pytorch/javacpp/PytorchJavaCPPInterface.java @@ -188,8 +188,11 @@ private void launchModelLoadOnProcess() throws IOException, InterruptedException throw new RuntimeException(); else if (task.status == TaskStatus.FAILED) throw new RuntimeException(); - else if (task.status == TaskStatus.CRASHED) + else if (task.status == TaskStatus.CRASHED) { + this.runner.close(); + runner = null; throw new RuntimeException(); + } } /** @@ -301,8 +304,11 @@ void runInterprocessing(List> inputTensors, List> outputTens throw new RuntimeException(); else if (task.status == TaskStatus.FAILED) throw new RuntimeException(); - else if (task.status == TaskStatus.CRASHED) + else if (task.status == TaskStatus.CRASHED) { + this.runner.close(); + runner = null; throw new RuntimeException(); + } for (int i = 0; i < outputTensors.size(); i ++) { String name = (String) Types.decode(encOuts.get(i)).get(MEM_NAME_KEY); SharedMemoryArray shm = shmaOutputList.stream() @@ -364,8 +370,11 @@ public void closeModel() { throw new RuntimeException(); else if (task.status == TaskStatus.FAILED) throw new RuntimeException(); - else if (task.status == TaskStatus.CRASHED) + else if (task.status == TaskStatus.CRASHED) { + this.runner.close(); + runner = null; throw new RuntimeException(); + } this.runner.close(); this.runner = null; return;