From 80bfa36ca03755350f4f94cd61d8f177ea1c5afa Mon Sep 17 00:00:00 2001 From: carlosuc3m <100329787@alumnos.uc3m.es> Date: Thu, 3 Oct 2024 17:54:57 +0200 Subject: [PATCH] handle crashes gracefully --- .../tensorflow/v1/Tensorflow1Interface.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/bioimage/modelrunner/tensorflow/v1/Tensorflow1Interface.java b/src/main/java/io/bioimage/modelrunner/tensorflow/v1/Tensorflow1Interface.java index 7aacf76..b134ad5 100644 --- a/src/main/java/io/bioimage/modelrunner/tensorflow/v1/Tensorflow1Interface.java +++ b/src/main/java/io/bioimage/modelrunner/tensorflow/v1/Tensorflow1Interface.java @@ -220,8 +220,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(); + } } /** @@ -377,8 +380,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() @@ -511,8 +517,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;