fix(std daq status): improvements to the status callbacks #35
@@ -468,11 +468,15 @@ class StdDaqClient:
|
||||
Run the count callbacks with the given count.
|
||||
The callbacks will be called with the count as argument.
|
||||
"""
|
||||
for cb in self._count_callbacks.values():
|
||||
callbacks_ids = list(self._count_callbacks.keys())
|
||||
for cb_id in callbacks_ids:
|
||||
if cb_id not in self._count_callbacks:
|
||||
continue
|
||||
cb = self._count_callbacks[cb_id]
|
||||
try:
|
||||
cb(count)
|
||||
except Exception as exc:
|
||||
logger.error(f"Error in StdDAQ count callback: {exc}")
|
||||
logger.error(f"Error in StdDAQ count callback with ID {cb_id}: {exc}")
|
||||
|
||||
def _run_status_callbacks(self):
|
||||
"""
|
||||
@@ -481,19 +485,25 @@ class StdDaqClient:
|
||||
or exception, respectively and removed from the list of callbacks.
|
||||
"""
|
||||
status = self._status
|
||||
completed_callbacks = []
|
||||
for dev_status, success, error in self._status_callbacks.values():
|
||||
if dev_status.done:
|
||||
logger.warning("Status object already resolved. Skipping StdDaq callback.")
|
||||
|
||||
status_callbacks_ids = list(self._status_callbacks.keys())
|
||||
for status_id in status_callbacks_ids:
|
||||
dev_status, success, error = self._status_callbacks.get(status_id, (None, [], []))
|
||||
if dev_status is None:
|
||||
continue
|
||||
|
||||
if dev_status.done:
|
||||
logger.info("Status object already resolved. Skipping StdDaq callback.")
|
||||
self._status_callbacks.pop(status_id)
|
||||
continue
|
||||
|
||||
if status in success:
|
||||
dev_status.set_finished()
|
||||
logger.info(f"StdDaq status is {status}")
|
||||
completed_callbacks.append(dev_status)
|
||||
elif status in error:
|
||||
self._status_callbacks.pop(status_id)
|
||||
continue
|
||||
|
||||
if status in error:
|
||||
logger.warning(f"StdDaq status is {status}")
|
||||
dev_status.set_exception(StdDaqError(f"StdDaq status is {status}"))
|
||||
completed_callbacks.append(dev_status)
|
||||
|
||||
for cb in completed_callbacks:
|
||||
self._status_callbacks.pop(id(cb))
|
||||
self._status_callbacks.pop(status_id)
|
||||
|
||||
Reference in New Issue
Block a user