Skip to content

Commit dc5917c

Browse files
committed
handle crashes gracefully
1 parent 1107e82 commit dc5917c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/main/java/io/bioimage/modelrunner/pytorch/PytorchInterface.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,11 @@ private void launchModelLoadOnProcess() throws IOException, InterruptedException
199199
throw new RuntimeException();
200200
else if (task.status == TaskStatus.FAILED)
201201
throw new RuntimeException();
202-
else if (task.status == TaskStatus.CRASHED)
202+
else if (task.status == TaskStatus.CRASHED) {
203+
this.runner.close();
204+
runner = null;
203205
throw new RuntimeException();
206+
}
204207
}
205208

206209
/**
@@ -321,8 +324,11 @@ void runInterprocessing(List<Tensor<T>> inputTensors, List<Tensor<R>> outputTens
321324
throw new RuntimeException();
322325
else if (task.status == TaskStatus.FAILED)
323326
throw new RuntimeException();
324-
else if (task.status == TaskStatus.CRASHED)
327+
else if (task.status == TaskStatus.CRASHED) {
328+
this.runner.close();
329+
runner = null;
325330
throw new RuntimeException();
331+
}
326332
for (int i = 0; i < outputTensors.size(); i ++) {
327333
String name = (String) Types.decode(encOuts.get(i)).get(MEM_NAME_KEY);
328334
SharedMemoryArray shm = shmaOutputList.stream()
@@ -455,8 +461,11 @@ public void closeModel() {
455461
throw new RuntimeException();
456462
else if (task.status == TaskStatus.FAILED)
457463
throw new RuntimeException();
458-
else if (task.status == TaskStatus.CRASHED)
464+
else if (task.status == TaskStatus.CRASHED) {
465+
this.runner.close();
466+
runner = null;
459467
throw new RuntimeException();
468+
}
460469
this.runner.close();
461470
this.runner = null;
462471
return;

0 commit comments

Comments
 (0)