Merge branch 'stitching-cancel' into 'v3'

Adjust catching of InvocationCancelledError so stiching reports as cancelled

See merge request openflexure/openflexure-microscope-server!637
This commit is contained in:
Julian Stirling 2026-07-02 14:17:12 +00:00
commit d7421ccea5

View file

@ -313,17 +313,19 @@ class SmartScanThing(OFMThing):
# If _scan_data is set then scan started
if self._scan_data is not None:
self._return_to_starting_position()
if not isinstance(e, scan_directories.NotEnoughFreeSpaceError):
# Don't stitch if drive is full (already logged)
self.logger.info(
"Attempting to stitch and archive the images acquired so far."
)
self._perform_final_stitch()
if self._ongoing_scan is not None:
# Save any final messages even if there is an exception.
self._ongoing_scan.save_scan_log(self)
# Error must be raised so UI gives correct output
raise e
except lt.exceptions.InvocationCancelledError as e:
# InvocationCancelledError is caught in `_run_scan` if it happens
# while scanning, but it propagates if it occurs during stitching.
# If raised we still need to save the scan log.
if self._ongoing_scan is not None:
self._ongoing_scan.save_scan_log(self)
# Reraise so the action reports as cancelled if stitching is cancelled.
raise e
finally:
# However the scan finishes, unset all variables and release lock
self._ongoing_scan = None
@ -728,9 +730,10 @@ class SmartScanThing(OFMThing):
)
try:
final_stitcher.run()
except lt.exceptions.InvocationCancelledError:
except lt.exceptions.InvocationCancelledError as e:
# Sleep for 1 second just to allow invocation logs to pass to user.
time.sleep(1)
raise e
except ChildProcessError as e:
self.logger.error(f"Stitching failed: {e}", exc_info=e)