From 4baad0d79ac1f07d643190307293d3a13d049df3 Mon Sep 17 00:00:00 2001 From: appel_c Date: Sun, 30 Nov 2025 16:10:39 +0100 Subject: [PATCH] wip; fixup add timing for on_connected --- superxas_bec/devices/timepix/timepix.py | 11 +++++++- .../timepix_fly_client/timepix_fly_backend.py | 25 ++++--------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/superxas_bec/devices/timepix/timepix.py b/superxas_bec/devices/timepix/timepix.py index be87301..ad12409 100644 --- a/superxas_bec/devices/timepix/timepix.py +++ b/superxas_bec/devices/timepix/timepix.py @@ -474,8 +474,12 @@ class Timepix(PSIDeviceBase, TimePixControl): No signals are connected at this point. If you like to set default values on signals, please use on_connected instead. """ + start_time = time.time() + logger.info(f"Loading default pixel map for TimePix detector {self.name}...") self.set_pixel_map_from_json_file(DEFAULT_PIXEL_MAP) - self.backend.on_init() + logger.info( + f"Default pixel map for TimePix detector {self.name} loaded after {time.time() - start_time:.3f} seconds." + ) def _enable_xes_settings(self, enabled: bool) -> None: """Enable XES specific settings for the TimePix detector.""" @@ -494,6 +498,8 @@ class Timepix(PSIDeviceBase, TimePixControl): Called after the device is connected and its signals are connected. Default values for signals should be set here. """ + start_time = time.time() + logger.info(f"Connecting TimePix detector {self.name}...") # Prepare TimePix Detector self._enable_xes_settings(self.enable_xes) self.cam.trigger_mode.set(TRIGGERMODE.INTERNAL).wait(timeout=self._pv_timeout) @@ -507,6 +513,9 @@ class Timepix(PSIDeviceBase, TimePixControl): # Register the callback for processing data received by the backend self.backend.add_callback(self.msg_buffer_callback) self._poll_thread.start() + logger.info( + f"TimePix detector {self.name} connected and initialized after {time.time() - start_time:.3f} seconds." + ) def on_stage(self) -> StatusBase | None: """Called while staging the device.""" diff --git a/superxas_bec/devices/timepix/timepix_fly_client/timepix_fly_backend.py b/superxas_bec/devices/timepix/timepix_fly_client/timepix_fly_backend.py index 17744e3..1999137 100644 --- a/superxas_bec/devices/timepix/timepix_fly_client/timepix_fly_backend.py +++ b/superxas_bec/devices/timepix/timepix_fly_client/timepix_fly_backend.py @@ -11,7 +11,6 @@ hooks for all the relevant ophyd interface, 'on_stage', from __future__ import annotations -import atexit import json import signal import socket @@ -77,32 +76,15 @@ class TimepixFlyBackend: self._socket_server: socket.socket | None = None self._data_thread: threading.Thread | None = None self._data_thread_shutdown_event = threading.Event() - # TODO remove custom atexit handler if ophyd device cleanup works properly - atexit.register(self.on_destroy) # Ensure cleanup on exit - self.on_init() ################################################### ###### Hooks for the PSIDeviceBase interface ###### ################################################### - # TODO remove - def on_init(self): - """Called during initialization of the device.""" - try: - - def sigint_handler(*args): - """Hook SIGINT signals to on_destroy.""" - self.on_destroy() - - signal.signal(signal.SIGINT, sigint_handler) - signal.signal(signal.SIGTERM, sigint_handler) - # pylint: disable=broad-except - except Exception: - logger.warning("Could not set signal handlers for SIGINT and SIGTERM.") - def on_connected(self): """Called if it is ensured that the device is connected.""" - + time_started = time.time() + logger.info("Connecting to Timepix Fly backend...") try: self.timepix_fly_client.on_connected() status = self.start_data_server() @@ -114,6 +96,9 @@ class TimepixFlyBackend: raise TimepixFlyBackendException( f"Could not start data server on {self.hostname}:{self.socket_port}. Please check logs for more details." ) + logger.info( + f"Timepix Fly backend connected and data server started on {self.hostname}:{self.socket_port} after {time.time() - time_started:.3f} seconds." + ) def on_stage(self, other_config: OtherConfigModel, pixel_map: PixelMap): """