diff --git a/csaxs_bec/devices/epics/mcs_card/mcs_card_csaxs.py b/csaxs_bec/devices/epics/mcs_card/mcs_card_csaxs.py index 5d54f50..f63af37 100644 --- a/csaxs_bec/devices/epics/mcs_card/mcs_card_csaxs.py +++ b/csaxs_bec/devices/epics/mcs_card/mcs_card_csaxs.py @@ -432,18 +432,24 @@ class MCSCardCSAXS(PSIDeviceBase, MCSCard): self._start_monitor_async_data_emission.clear() # Stop monitoring # NOTE Important check as set_finished or set_exception should not be called # if the status is already done (e.g. cancelled externally) - logger.info(f"Status callback called for {self.name}, exception: {exception}") - if status.done: - return # Already done and cancelled externally. - if exception: - status.set_exception(exception) - else: - status.set_finished() + logger.info( + f"Status callback called for {self.name}, exception: {exception} of status {status}." + ) + with self._rlock: + if status.done: + return # Already done and cancelled externally. + if exception is not None: + logger.info(f"Setting exception for status of {self.name} in complete.") + status.set_exception(exception) + else: + logger.info(f"Setting finished for status of {self.name} in complete.") + status.set_finished() def _status_failed_callback(self, status: StatusBase) -> None: """Callback for status failure, the monitoring thread should be stopped.""" # NOTE Check for status.done and status.success is important to avoid if status.done: + self._start_monitor_async_data_emission.clear() # Stop monitoring def on_complete(self) -> CompareStatus: