Acquire microscope lock for state and settings IO

This commit is contained in:
Joel Collins 2020-06-15 16:19:33 +01:00
parent 5d70d5f7fe
commit 1c1dcdbe1a

View file

@ -153,6 +153,7 @@ class Microscope:
Return: Return:
dict: Dictionary containing complete microscope state dict: Dictionary containing complete microscope state
""" """
with self.lock:
state = {"camera": self.camera.state, "stage": self.stage.state} state = {"camera": self.camera.state, "stage": self.stage.state}
return state return state
@ -160,6 +161,7 @@ class Microscope:
""" """
Applies a settings dictionary to the microscope. Missing parameters will be left untouched. Applies a settings dictionary to the microscope. Missing parameters will be left untouched.
""" """
with self.lock:
logging.debug("Microscope: Applying settings: {}".format(settings)) logging.debug("Microscope: Applying settings: {}".format(settings))
# If attached to a camera # If attached to a camera
@ -197,6 +199,7 @@ class Microscope:
This is to ensure that settings for currently disconnected hardware This is to ensure that settings for currently disconnected hardware
don't get removed from the settings file. don't get removed from the settings file.
""" """
with self.lock:
settings_current = { settings_current = {
"id": self.id, "id": self.id,
@ -341,7 +344,7 @@ class Microscope:
) )
# Gether metadata from hardware in a greenlet # Gether metadata from hardware in a greenlet
gevent.spawn(self.add_metadata_to_capture, output, metadata, annotations, tags) gevent.get_hub().threadpool.spawn(self.add_metadata_to_capture, output, metadata, annotations, tags)
logging.info(f"Finished capture to {output.file}") logging.info(f"Finished capture to {output.file}")