Skip to content

Commit

Permalink
set_value is possibly re-entrant locking to make sure execution order
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-oscarsson committed Jan 31, 2025
1 parent 0ce6c1e commit 217bfca
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions mxcubecore/HardwareObjects/abstract/AbstractActuator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from ast import literal_eval

from mxcubecore.BaseHardwareObjects import HardwareObject
from gevent.lock import RLock

__copyright__ = """ Copyright © 2010-2022 by the MXCuBE collaboration """
__license__ = "LGPLv3+"
Expand All @@ -50,6 +51,7 @@ def __init__(self, name):
self.read_only = False
self.default_value = None
self.username = None
self._lock = RLock()

def init(self):
"""Initialise actuator_name, username, read_only and default_value
Expand Down Expand Up @@ -130,16 +132,18 @@ def set_value(self, value, timeout=0):
ValueError: Invalid value or attemp to set read only actuator.
RuntimeError: Timeout waiting for status ready # From wait_ready
"""
if self.read_only:
raise ValueError("Attempt to set value for read-only Actuator")
if self.validate_value(value):
self._set_value(value)
self.update_value()
if timeout == 0:
return
self.wait_ready(timeout)
else:
raise ValueError(f"Invalid value {value}")

with self._lock:
if self.read_only:
raise ValueError("Attempt to set value for read-only Actuator")
if self.validate_value(value):
self._set_value(value)
self.update_value()
if timeout == 0:
return
self.wait_ready(timeout)
else:
raise ValueError(f"Invalid value {value}")

def update_value(self, value=None):
"""Check if the value has changed. Emits signal valueChanged.
Expand Down

0 comments on commit 217bfca

Please sign in to comment.