From feec53aa1ff0a9e6a27f5a9ae607859cddb3c2fd Mon Sep 17 00:00:00 2001 From: jaknapper Date: Thu, 7 Aug 2025 17:56:34 +0100 Subject: [PATCH 1/3] Custom out of memory error --- src/openflexure_microscope_server/stitching.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/openflexure_microscope_server/stitching.py b/src/openflexure_microscope_server/stitching.py index b88c4036..6d74a4a8 100644 --- a/src/openflexure_microscope_server/stitching.py +++ b/src/openflexure_microscope_server/stitching.py @@ -24,6 +24,10 @@ DEFAULT_OVERLAP = 0.1 DEFAULT_RESIZE = 0.5 +class SubprocessOOMKilledError(MemoryError): + """Exception called when stitch is killed by Linux out of memory.""" + + class StitcherValidationError(RuntimeError): """The stitcher received values that it deems unsafe to create a command from.""" @@ -290,8 +294,14 @@ class FinalStitcher(BaseStitcher): if process.poll() == 0: self.logger.info("Stitching complete") + elif process.poll() == -9: + raise SubprocessOOMKilledError( + "Stitching was killed due to insufficient memory." + ) else: - raise ChildProcessError(f"Subprocess {STITCHING_CMD} exited with an error.") + raise ChildProcessError( + f"Subprocess {STITCHING_CMD} errored with exit code {process.poll()}." + ) def _log_ongoing( self, From 4d3215242756000a887baf90be74ba6ff081a49f Mon Sep 17 00:00:00 2001 From: jaknapper Date: Thu, 7 Aug 2025 18:10:02 +0100 Subject: [PATCH 2/3] Custom Memory error changed to generic sigkill --- src/openflexure_microscope_server/stitching.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/openflexure_microscope_server/stitching.py b/src/openflexure_microscope_server/stitching.py index 6d74a4a8..e7ba5730 100644 --- a/src/openflexure_microscope_server/stitching.py +++ b/src/openflexure_microscope_server/stitching.py @@ -24,8 +24,8 @@ DEFAULT_OVERLAP = 0.1 DEFAULT_RESIZE = 0.5 -class SubprocessOOMKilledError(MemoryError): - """Exception called when stitch is killed by Linux out of memory.""" +class SigkillError(ChildProcessError): + """Exception called when stitch is killed by Sigkill.""" class StitcherValidationError(RuntimeError): @@ -295,8 +295,9 @@ class FinalStitcher(BaseStitcher): if process.poll() == 0: self.logger.info("Stitching complete") elif process.poll() == -9: - raise SubprocessOOMKilledError( - "Stitching was killed due to insufficient memory." + raise SigkillError( + "Stitching was killed by an external process. This is " + "most likely due to running out of memory." ) else: raise ChildProcessError( From 1e368aef815b3ea4ace5071e7022f9bae4af13d5 Mon Sep 17 00:00:00 2001 From: Joe Knapper Date: Wed, 13 Aug 2025 16:52:00 +0000 Subject: [PATCH 3/3] Apply suggestions from code review of branch log-oom-error Co-authored-by: Julian Stirling --- src/openflexure_microscope_server/stitching.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/openflexure_microscope_server/stitching.py b/src/openflexure_microscope_server/stitching.py index e7ba5730..44f2609f 100644 --- a/src/openflexure_microscope_server/stitching.py +++ b/src/openflexure_microscope_server/stitching.py @@ -24,8 +24,8 @@ DEFAULT_OVERLAP = 0.1 DEFAULT_RESIZE = 0.5 -class SigkillError(ChildProcessError): - """Exception called when stitch is killed by Sigkill.""" +class ExternalSigkillError(ChildProcessError): + """Exception called when stitch is killed by an external process calling Sigkill.""" class StitcherValidationError(RuntimeError): @@ -295,7 +295,7 @@ class FinalStitcher(BaseStitcher): if process.poll() == 0: self.logger.info("Stitching complete") elif process.poll() == -9: - raise SigkillError( + raise ExternalSigkillError( "Stitching was killed by an external process. This is " "most likely due to running out of memory." )