diff --git a/devices.py b/devices.py index 771f102..75f9119 100644 --- a/devices.py +++ b/devices.py @@ -27,12 +27,11 @@ SEC Node with added functionality for starting and stopping frappy servers connected to a SEC node """ -import time import threading from nicos import config, session from nicos.core import Override, Param, Moveable, status, POLLER, SIMULATION, DeviceAlias, \ Device, anytype, listof -from nicos.devices.secop.devices import SecNodeDevice +from nicos.devices.secop.devices import SecNodeDevice, NicosSecopClient from nicos.core.utils import USER, User, createThread from nicos.services.daemon.script import RequestError, ScriptRequest from nicos.utils.comparestrings import compare @@ -107,9 +106,9 @@ def all_info(all_cfg, prefix='currently configured: '): def get_frappy_config(): try: - return session.devices['frappy_config'] + return session.devices['frappy'] except KeyError: - session.log.error("'frappy_config' is not available - 'frappy' setup is not loaded") + session.log.error("the frappy device is not available - 'frappy' setup is not loaded") return None @@ -155,11 +154,12 @@ class FrappyConfig(Device): def handle_notifications(self): controller = session.daemon_device._controller while True: - self._trigger_change.wait() + # we do not wait for ever here, because there might be changes + # on an unconnected service + self._trigger_change.wait(60) self._trigger_change.clear() - time.sleep(2) - if self._trigger_change.is_set(): - continue + while self._trigger_change.wait(2): # triggered again within 2 sec + self._trigger_change.clear() try: cfgs = self.check_services() guess_info = self.to_consider(cfgs) @@ -491,9 +491,7 @@ class FrappyNode(SecNodeDevice, Moveable): if isinstance(cfg, str): # may also be None or True self.restart(cfg) if cfg is None: # None means: server is not running, and does not need to be restarted - # connect in background, as the server might be started later - createThread('connect', self._connect) - # TODO: check if it is not better to add a try_period argument to SecNode._connect() + self._disconnect() return try: self._connect()