diff --git a/openflexure_microscope/plugins/example/plugin.py b/openflexure_microscope/plugins/example/plugin.py index 3638a57f..a0fb0538 100644 --- a/openflexure_microscope/plugins/example/plugin.py +++ b/openflexure_microscope/plugins/example/plugin.py @@ -39,12 +39,12 @@ class Plugin(MicroscopePlugin): print("Starting a long-running task...") n_array = [] - print("Acquiring camera lock...") - with self.microscope.camera.lock: + print("Acquiring camera and stage locks...") + with self.microscope.camera.lock, self.microscope.stage.lock: for _ in range(t_run): n_array.append(random.random()) time.sleep(1) - print("Long-running task finished! Releasing lock.") + print("Long-running task finished! Releasing locks.") return n_array \ No newline at end of file diff --git a/openflexure_microscope/stage/openflexure.py b/openflexure_microscope/stage/openflexure.py index 2703da35..5d6e745b 100644 --- a/openflexure_microscope/stage/openflexure.py +++ b/openflexure_microscope/stage/openflexure.py @@ -7,4 +7,11 @@ class Stage(OpenFlexureStage): def __init__(self, *args, **kwargs): self.lock = StrictLock(timeout=2) #: Strict lock controlling thread access to camera hardware - OpenFlexureStage.__init__(self, *args, **kwargs) \ No newline at end of file + OpenFlexureStage.__init__(self, *args, **kwargs) + + def _move_rel_nobacklash(self, *args, **kwargs): + """ + Overrides `OpenFlexureStage._move_rel_nobacklash` to acquire lock first. + """ + with self.lock: + OpenFlexureStage._move_rel_nobacklash(self, *args, **kwargs) \ No newline at end of file