Merge branch 'variable-lock-timeout' into 'master'
Variable lock timeout See merge request openflexure/openflexure-microscope-server!64
This commit is contained in:
commit
768b005fe1
5 changed files with 52 additions and 52 deletions
|
|
@ -23,7 +23,7 @@ class BaseCamera(metaclass=ABCMeta):
|
||||||
self.thread = None
|
self.thread = None
|
||||||
self.camera = None
|
self.camera = None
|
||||||
|
|
||||||
self.lock = StrictLock(name="Camera", timeout=None)
|
self.lock = StrictLock(name="Camera", timeout=1)
|
||||||
|
|
||||||
self.frame = None
|
self.frame = None
|
||||||
self.last_access = 0
|
self.last_access = 0
|
||||||
|
|
@ -55,7 +55,7 @@ class BaseCamera(metaclass=ABCMeta):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def update_settings(self, config: dict):
|
def update_settings(self, config: dict):
|
||||||
"""Update settings from a config dictionary"""
|
"""Update settings from a config dictionary"""
|
||||||
with self.lock:
|
with self.lock(timeout=None):
|
||||||
# Apply valid config params to camera object
|
# Apply valid config params to camera object
|
||||||
for key, value in config.items(): # For each provided setting
|
for key, value in config.items(): # For each provided setting
|
||||||
if hasattr(self, key): # If the instance has a matching property
|
if hasattr(self, key): # If the instance has a matching property
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,7 @@ class PiCameraStreamer(BaseCamera):
|
||||||
logging.debug("PiCameraStreamer: Applying config:")
|
logging.debug("PiCameraStreamer: Applying config:")
|
||||||
logging.debug(config)
|
logging.debug(config)
|
||||||
|
|
||||||
with self.lock:
|
with self.lock(timeout=None):
|
||||||
|
|
||||||
# Apply valid config params to Picamera object
|
# Apply valid config params to Picamera object
|
||||||
if not self.record_active: # If not recording a video
|
if not self.record_active: # If not recording a video
|
||||||
|
|
@ -301,7 +301,7 @@ class PiCameraStreamer(BaseCamera):
|
||||||
"""
|
"""
|
||||||
Change the camera zoom, handling re-centering and scaling.
|
Change the camera zoom, handling re-centering and scaling.
|
||||||
"""
|
"""
|
||||||
with self.lock:
|
with self.lock(timeout=None):
|
||||||
self.zoom_value = float(zoom_value)
|
self.zoom_value = float(zoom_value)
|
||||||
if self.zoom_value < 1:
|
if self.zoom_value < 1:
|
||||||
self.zoom_value = 1
|
self.zoom_value = 1
|
||||||
|
|
@ -448,7 +448,7 @@ class PiCameraStreamer(BaseCamera):
|
||||||
resolution ((int, int)): Resolution to set the camera to, before starting recording.
|
resolution ((int, int)): Resolution to set the camera to, before starting recording.
|
||||||
Defaults to `self.stream_resolution`.
|
Defaults to `self.stream_resolution`.
|
||||||
"""
|
"""
|
||||||
with self.lock:
|
with self.lock(timeout=None):
|
||||||
# If stream object was destroyed
|
# If stream object was destroyed
|
||||||
if not hasattr(self, "stream"):
|
if not hasattr(self, "stream"):
|
||||||
self.stream = io.BytesIO() # Create a stream object
|
self.stream = io.BytesIO() # Create a stream object
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ class Microscope:
|
||||||
Return:
|
Return:
|
||||||
dict: Dictionary containing complete microscope state
|
dict: Dictionary containing complete microscope state
|
||||||
"""
|
"""
|
||||||
with self.lock:
|
with self.lock(timeout=None):
|
||||||
state = {"camera": self.camera.state, "stage": self.stage.state}
|
state = {"camera": self.camera.state, "stage": self.stage.state}
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
|
@ -161,7 +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:
|
with self.lock(timeout=None):
|
||||||
logging.debug("Microscope: Applying settings: {}".format(settings))
|
logging.debug("Microscope: Applying settings: {}".format(settings))
|
||||||
|
|
||||||
# If attached to a camera
|
# If attached to a camera
|
||||||
|
|
@ -199,39 +199,38 @@ 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 = {
|
||||||
|
"id": self.id,
|
||||||
settings_current = {
|
"name": self.name,
|
||||||
"id": self.id,
|
"fov": self.fov,
|
||||||
"name": self.name,
|
"extensions": self.extension_settings,
|
||||||
"fov": self.fov,
|
}
|
||||||
"extensions": self.extension_settings,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
with self.lock(timeout=None):
|
||||||
# If attached to a camera
|
# If attached to a camera
|
||||||
if self.camera:
|
if self.camera:
|
||||||
settings_current_camera = self.camera.read_settings()
|
settings_current_camera = self.camera.read_settings()
|
||||||
settings_current["camera"] = settings_current_camera
|
settings_current["camera"] = settings_current_camera
|
||||||
|
|
||||||
# Store an encoded copy of the PiCamera lens shading table, if it exists
|
# Store an encoded copy of the PiCamera lens shading table, if it exists
|
||||||
if hasattr(self.camera, "read_lens_shading_table"):
|
if hasattr(self.camera, "read_lens_shading_table"):
|
||||||
# Read LST. Returns None if no LST is active
|
# Read LST. Returns None if no LST is active
|
||||||
lst_arr = self.camera.read_lens_shading_table()
|
lst_arr = self.camera.read_lens_shading_table()
|
||||||
|
|
||||||
if lst_arr is not None:
|
if lst_arr is not None:
|
||||||
b64_string, dtype, shape = serialise_array_b64(lst_arr)
|
b64_string, dtype, shape = serialise_array_b64(lst_arr)
|
||||||
|
|
||||||
settings_current["camera"]["lens_shading_table"] = {
|
settings_current["camera"]["lens_shading_table"] = {
|
||||||
"@type": "ndarray",
|
"@type": "ndarray",
|
||||||
"b64_string": b64_string,
|
"b64_string": b64_string,
|
||||||
"dtype": dtype,
|
"dtype": dtype,
|
||||||
"shape": shape,
|
"shape": shape,
|
||||||
}
|
}
|
||||||
|
|
||||||
# If attached to a stage
|
# If attached to a stage
|
||||||
if self.stage:
|
if self.stage:
|
||||||
settings_current_stage = self.stage.read_settings()
|
settings_current_stage = self.stage.read_settings()
|
||||||
settings_current["stage"] = settings_current_stage
|
settings_current["stage"] = settings_current_stage
|
||||||
|
|
||||||
# Capture manager
|
# Capture manager
|
||||||
settings_current_captures = self.captures.read_settings()
|
settings_current_captures = self.captures.read_settings()
|
||||||
|
|
@ -255,27 +254,28 @@ class Microscope:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def configuration(self):
|
def configuration(self):
|
||||||
initial_configuration = self.configuration_file.load()
|
with self.lock(timeout=None):
|
||||||
|
initial_configuration = self.configuration_file.load()
|
||||||
|
|
||||||
current_configuration = {
|
current_configuration = {
|
||||||
"application": {
|
"application": {
|
||||||
"name": "openflexure-microscope-server",
|
"name": "openflexure-microscope-server",
|
||||||
"version": pkg_resources.get_distribution(
|
"version": pkg_resources.get_distribution(
|
||||||
"openflexure-microscope-server"
|
"openflexure-microscope-server"
|
||||||
).version,
|
).version,
|
||||||
},
|
},
|
||||||
"stage": {
|
"stage": {
|
||||||
"type": self.stage.__class__.__name__,
|
"type": self.stage.__class__.__name__,
|
||||||
**self.stage.configuration,
|
**self.stage.configuration,
|
||||||
},
|
},
|
||||||
"camera": {
|
"camera": {
|
||||||
"type": self.camera.__class__.__name__,
|
"type": self.camera.__class__.__name__,
|
||||||
**self.camera.configuration,
|
**self.camera.configuration,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
initial_configuration.update(current_configuration)
|
initial_configuration.update(current_configuration)
|
||||||
return initial_configuration
|
return initial_configuration
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def metadata(self):
|
def metadata(self):
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ class BaseStage(metaclass=ABCMeta):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.lock = StrictLock(name="Stage", timeout=5)
|
self.lock = StrictLock(name="Stage", timeout=1)
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def update_settings(self, config: dict):
|
def update_settings(self, config: dict):
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class SangaStage(BaseStage):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def position(self):
|
def position(self):
|
||||||
with self.lock:
|
with self.lock(timeout=None):
|
||||||
return self.board.position
|
return self.board.position
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue