diff --git a/superxas_bec/devices/timepix/timepix.py b/superxas_bec/devices/timepix/timepix.py index cdbfe74..bcb6be5 100644 --- a/superxas_bec/devices/timepix/timepix.py +++ b/superxas_bec/devices/timepix/timepix.py @@ -63,13 +63,14 @@ class AndStatus(StatusBase): with self._lock: if self._externally_initiated_completion: return + if self.done: # Return if status is already done.. It must be resolved already + return for st in self.all_statuses: with st._lock: - if not self.done: - if st.done and not st.success: - self.set_exception(st.exception()) - return + if st.done and not st.success: + self.set_exception(st.exception()) + return if all(st.done for st in self.all_statuses) and all( st.success for st in self.all_statuses diff --git a/superxas_bec/devices/timepix/timepix_fly_client/timepix_fly_client.py b/superxas_bec/devices/timepix/timepix_fly_client/timepix_fly_client.py index 6137093..546712c 100644 --- a/superxas_bec/devices/timepix/timepix_fly_client/timepix_fly_client.py +++ b/superxas_bec/devices/timepix/timepix_fly_client/timepix_fly_client.py @@ -261,24 +261,25 @@ class TimepixFlyClient: callback_ids = list(self._status_callbacks.keys()) for cb_id in callback_ids: dev_status, success, error = self._status_callbacks[cb_id] - if dev_status.done: - self._status_callbacks.pop(cb_id) - continue - if status in success: - dev_status.set_finished() - logger.info(f"Status callback finished in succes: {status.value}") - self._status_callbacks.pop(cb_id) - elif status in error: - last_error = self.last_error() - logger.error( - f"Timepix status in error is {status.value}, with last error: {last_error.message}" - ) - dev_status.set_exception( - TimePixStatusError( - f"TimePixStatus status is '{status.value},' last error message: {last_error.message}" + with dev_status._lock: + if dev_status.done: + self._status_callbacks.pop(cb_id) + continue + if status in success: + dev_status.set_finished() + logger.info(f"Status callback finished in succes: {status.value}") + self._status_callbacks.pop(cb_id) + elif status in error: + last_error = self.last_error() + logger.error( + f"Timepix status in error is {status.value}, with last error: {last_error.message}" ) - ) - self._status_callbacks.pop(cb_id) + dev_status.set_exception( + TimePixStatusError( + f"TimePixStatus status is '{status.value},' last error message: {last_error.message}" + ) + ) + self._status_callbacks.pop(cb_id) # Reset the _started flag if the status is in CONFIG. if status == TimePixFlyStatus.CONFIG: self._started = False # Should this be made thread-safe?