wip; fixup add timing for on_connected
This commit is contained in:
@@ -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."""
|
||||
|
||||
@@ -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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user