Skip to content

Commit 050116e

Browse files
committed
handle crashes gracefully
1 parent e21a11f commit 050116e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/main/java/io/bioimage/modelrunner/pytorch/javacpp/PytorchJavaCPPInterface.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,11 @@ private void launchModelLoadOnProcess() throws IOException, InterruptedException
188188
throw new RuntimeException();
189189
else if (task.status == TaskStatus.FAILED)
190190
throw new RuntimeException();
191-
else if (task.status == TaskStatus.CRASHED)
191+
else if (task.status == TaskStatus.CRASHED) {
192+
this.runner.close();
193+
runner = null;
192194
throw new RuntimeException();
195+
}
193196
}
194197

195198
/**
@@ -301,8 +304,11 @@ void runInterprocessing(List<Tensor<T>> inputTensors, List<Tensor<R>> outputTens
301304
throw new RuntimeException();
302305
else if (task.status == TaskStatus.FAILED)
303306
throw new RuntimeException();
304-
else if (task.status == TaskStatus.CRASHED)
307+
else if (task.status == TaskStatus.CRASHED) {
308+
this.runner.close();
309+
runner = null;
305310
throw new RuntimeException();
311+
}
306312
for (int i = 0; i < outputTensors.size(); i ++) {
307313
String name = (String) Types.decode(encOuts.get(i)).get(MEM_NAME_KEY);
308314
SharedMemoryArray shm = shmaOutputList.stream()
@@ -364,8 +370,11 @@ public void closeModel() {
364370
throw new RuntimeException();
365371
else if (task.status == TaskStatus.FAILED)
366372
throw new RuntimeException();
367-
else if (task.status == TaskStatus.CRASHED)
373+
else if (task.status == TaskStatus.CRASHED) {
374+
this.runner.close();
375+
runner = null;
368376
throw new RuntimeException();
377+
}
369378
this.runner.close();
370379
this.runner = null;
371380
return;

0 commit comments

Comments
 (0)