From 51e1388aaa9f1f3cd9dc97abec02473ed4fa6ed1 Mon Sep 17 00:00:00 2001 From: M*C*O Date: Fri, 19 Apr 2024 18:40:55 +0000 Subject: [PATCH] Fix: cleanup working dir after blender has exited --- src/main/java/com/sheepit/client/Client.java | 8 +------- src/main/java/com/sheepit/client/Job.java | 17 +++++++++++------ .../java/com/sheepit/client/RenderProcess.java | 3 +++ src/main/java/com/sheepit/client/os/OS.java | 11 ++++++++++- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/sheepit/client/Client.java b/src/main/java/com/sheepit/client/Client.java index 0e2ce95..7521a14 100644 --- a/src/main/java/com/sheepit/client/Client.java +++ b/src/main/java/com/sheepit/client/Client.java @@ -778,14 +778,8 @@ import okhttp3.HttpUrl; if (err != Error.Type.OK) { this.log.error("Client::work problem with runRenderer (ret " + err + ")"); - if (err == Error.Type.RENDERER_CRASHED_PYTHON_ERROR) { - this.log.error("Client::work failed with python error, cleaning directory in hope to recover"); - this.configuration.cleanWorkingDirectory(); - } - return err; } - - return Error.Type.OK; + return err; } protected Error.Type downloadSceneFile(Job ajob_) throws SheepItException { diff --git a/src/main/java/com/sheepit/client/Job.java b/src/main/java/com/sheepit/client/Job.java index 1b8c3cf..e51c163 100644 --- a/src/main/java/com/sheepit/client/Job.java +++ b/src/main/java/com/sheepit/client/Job.java @@ -485,6 +485,7 @@ import java.util.regex.Pattern; // Put back base icon gui.updateTrayIcon(Job.SHOW_BASE_ICON); process.kill(); + maybeCleanWorkingDir(error); for (String logline : configuration.filesystemHealthCheck()) { log.debug(logline); } @@ -804,7 +805,6 @@ import java.util.regex.Pattern; //30-11 01:16:57 (debug) Color management: scene view "AgX" not found, setting default "Standard". //30-11 01:16:57 (debug) Color management: scene look "AgX - Medium High Contrast" not found, setting default "None". //30-11 01:16:57 (debug) Color management: image colorspace "Linear Rec.709" not found, will use default instead. - configuration.cleanWorkingDirectory(); return Type.COLOR_MANAGEMENT_ERROR; } } @@ -814,7 +814,6 @@ import java.util.regex.Pattern; //28-11 12:43:40 (debug) Fra:340 Mem:11.68M (Peak 28.28M) | Time:00:01.69 | Compositing | De-initializing execution //28-11 12:43:40 (debug) OpenColorIO Error: The specified file reference 'srgb_inv.spi1d' could not be located. The following attempts were made: 'E:\SheepIt\sheepit\6b752e00cd23e1789e00285310cb6845\3.6\datafiles\colormanagement\luts\srgb_inv.spi1d' : 'E:\SheepIt\sheepit\6b752e00cd23e1789e00285310cb6845\3.6\datafiles\colormanagement\filmic\srgb_inv.spi1d'. //28-11 12:43:40 (debug) Saved: 'E:\SheepIt\sheepit\1_0340.png' - configuration.cleanWorkingDirectory(); return Type.COLOR_MANAGEMENT_ERROR; } else if (line.contains("CUDA error: Out of memory")) { @@ -942,7 +941,6 @@ import java.util.regex.Pattern; // Fatal Python error: Py_Initialize: unable to load the file system codec // ImportError: No module named 'encodings' // Current thread 0x0000388c (most recent call first): - configuration.cleanWorkingDirectory(); return Error.Type.RENDERER_CRASHED_PYTHON_ERROR; } else if (line.contains("Calloc returns null")) { @@ -990,11 +988,9 @@ import java.util.regex.Pattern; return Error.Type.GPU_NOT_SUPPORTED; } else if (line.contains("Engine 'CYCLES' not available for scene") || line.contains("Engine 'BLENDER_EEVEE' not available for scene") || line.contains("Engine 'BLENDER_WORKBENCH' not available for scene") || line.contains("Engine 'HYDRA_STORM' not available for scene")) { - configuration.cleanWorkingDirectory(); return Error.Type.ENGINE_NOT_AVAILABLE; } else if (line.contains("Warning: Cycles is not enabled!")) { - configuration.cleanWorkingDirectory(); return Error.Type.ENGINE_NOT_AVAILABLE; } else if (line.contains("OpenImageDenoise error: SSE4.1 support is required at minimum") || line.contains("OpenImageDenoiser is not supported on this CPU:") || line.contains("No device available to denoise on")) { @@ -1040,13 +1036,22 @@ import java.util.regex.Pattern; //Read prefs: /home/raimund/.config/blender/3.3/config/userpref.blend ///run/user/1000/gvfs/ non-existent directory //DETECT_DEVICE_ERRORR: Couldn't find OPTIX device with id CUDA_NVIDIA GeForce GTX 1080_0000:01:00_OptiX - configuration.cleanWorkingDirectory(); return Error.Type.DETECT_DEVICE_ERROR; } return Type.OK; } + private void maybeCleanWorkingDir(Type error) { + boolean cleanup = Type.COLOR_MANAGEMENT_ERROR == error + || Type.RENDERER_CRASHED_PYTHON_ERROR == error + || Type.ENGINE_NOT_AVAILABLE == error + || Type.DETECT_DEVICE_ERROR == error; + if (cleanup) { + configuration.cleanWorkingDirectory(); + } + } + public static class renderStartedObservable extends Observable { @Getter private boolean isStarted; diff --git a/src/main/java/com/sheepit/client/RenderProcess.java b/src/main/java/com/sheepit/client/RenderProcess.java index 1504405..ecc9924 100644 --- a/src/main/java/com/sheepit/client/RenderProcess.java +++ b/src/main/java/com/sheepit/client/RenderProcess.java @@ -114,6 +114,9 @@ import oshi.software.os.OSProcess; } catch (NullPointerException ex) { // We are racing the system itself, we can't avoid catching NPE's log.debug("RenderProcess::Handled process becoming unavailable before getting killed"); } + catch (InterruptedException e) { + log.debug("OS::kill got interrupted while sleeping"); + } } } diff --git a/src/main/java/com/sheepit/client/os/OS.java b/src/main/java/com/sheepit/client/os/OS.java index 7b3310c..fc4e0ac 100644 --- a/src/main/java/com/sheepit/client/os/OS.java +++ b/src/main/java/com/sheepit/client/os/OS.java @@ -145,9 +145,18 @@ public abstract class OS { * @param proc Process to kill * @return true if proc wasn't null and was destroyed */ - public boolean kill(Process proc) { + public boolean kill(Process proc) throws InterruptedException { if (proc != null) { proc.destroy(); + + for (int i = 0; i <= 30; i++) { + if (proc.isAlive() == false) { + return true; + } + java.lang.Thread.sleep(100); + } + + proc.destroyForcibly(); return true; } return false;