Added lock to stage positioning
This commit is contained in:
parent
18dec56c80
commit
4be89866ee
2 changed files with 11 additions and 4 deletions
|
|
@ -39,12 +39,12 @@ class Plugin(MicroscopePlugin):
|
||||||
print("Starting a long-running task...")
|
print("Starting a long-running task...")
|
||||||
n_array = []
|
n_array = []
|
||||||
|
|
||||||
print("Acquiring camera lock...")
|
print("Acquiring camera and stage locks...")
|
||||||
with self.microscope.camera.lock:
|
with self.microscope.camera.lock, self.microscope.stage.lock:
|
||||||
for _ in range(t_run):
|
for _ in range(t_run):
|
||||||
n_array.append(random.random())
|
n_array.append(random.random())
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
print("Long-running task finished! Releasing lock.")
|
print("Long-running task finished! Releasing locks.")
|
||||||
|
|
||||||
return n_array
|
return n_array
|
||||||
|
|
@ -7,4 +7,11 @@ class Stage(OpenFlexureStage):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.lock = StrictLock(timeout=2) #: Strict lock controlling thread access to camera hardware
|
self.lock = StrictLock(timeout=2) #: Strict lock controlling thread access to camera hardware
|
||||||
|
|
||||||
OpenFlexureStage.__init__(self, *args, **kwargs)
|
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)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue