Loading openflexure_microscope/plugins/example/plugin.py +3 −3 Original line number Diff line number Diff line Loading @@ -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 openflexure_microscope/stage/openflexure.py +7 −0 Original line number Diff line number Diff line Loading @@ -8,3 +8,10 @@ class Stage(OpenFlexureStage): self.lock = StrictLock(timeout=2) #: Strict lock controlling thread access to camera hardware 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 Loading
openflexure_microscope/plugins/example/plugin.py +3 −3 Original line number Diff line number Diff line Loading @@ -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
openflexure_microscope/stage/openflexure.py +7 −0 Original line number Diff line number Diff line Loading @@ -8,3 +8,10 @@ class Stage(OpenFlexureStage): self.lock = StrictLock(timeout=2) #: Strict lock controlling thread access to camera hardware 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