Run check background aonly fter scan variables are stored

This commit is contained in:
Julian Stirling 2025-04-10 11:45:57 +01:00
parent 83d2930d1f
commit 040373ef88
2 changed files with 9 additions and 7 deletions

View file

@ -76,7 +76,7 @@ class OFMHandler(logging.Handler):
def append_record(self, record):
"""
Use the built in formatter to format the record, then save
it to an array. Pop any in excess of the mamimum number of logs
it to an array. Pop any in excess of the maximum number of logs
"""
self._log.append(self.format(record))
while len(self._log) > self._max_logs:

View file

@ -193,8 +193,7 @@ class SmartScanThing(Thing):
background_detect Thing).
"""
self._check_background_is_set(background_detect)
started_scan = False
locked = self._scan_lock.acquire(timeout=0.1)
if not locked:
raise RuntimeError("Trying to run scan while scan is already running!")
@ -211,14 +210,17 @@ class SmartScanThing(Thing):
self._scan_images_taken = 0
try:
self._check_background_is_set()
self._ongoing_scan_name = self._get_uniuqe_scan_name_and_dir(scan_name)
overlap = self.overlap
# record starting position so we can return there
self._starting_position = self._stage.position
started_scan = True
self._run_scan(scan_name, overlap)
except Exception as e:
self._return_to_starting_position()
self._perform_final_stitch(overlap)
if started_scan:
self._return_to_starting_position()
self._perform_final_stitch(overlap)
# Error must be raised so UI gives correct output
raise e
finally:
@ -235,14 +237,14 @@ class SmartScanThing(Thing):
self._scan_images_taken = None
self._scan_lock.release()
def _check_background_is_set(self, background_detect):
def _check_background_is_set(self):
"""Before starting a scand check that we've got a background set
Raise error if it is not set but backroung detect is being used.
"""
if self.skip_background:
d = background_detect.background_distributions
d = self._background_detect.background_distributions
if not d:
raise RuntimeError(
"Background is not set: you need to calibrate background detection."