From def9f58252937d629a58fb0d7b7d767deba00c6c Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Tue, 28 Jan 2025 18:14:11 +0100 Subject: [PATCH] fixed stacklevel of warnings; added retry for reference undulator --- devices/undulator.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/devices/undulator.py b/devices/undulator.py index 730c899..9b22128 100644 --- a/devices/undulator.py +++ b/devices/undulator.py @@ -37,13 +37,13 @@ class Undulators(Adjustable): n_und_ref = machine_n_und_ref if n_und_ref != machine_n_und_ref: - log.warning(f"the chosen reference undulator ({n_und_ref}) is not the reference undulator currently used by the machine ({machine_n_und_ref})") + log.warning(f"the chosen reference undulator ({n_und_ref}) is not the reference undulator currently used by the machine ({machine_n_und_ref})", stacklevel=3) n_unds = list(n_unds) if N_UND_CHIC in n_unds: - log.warning(f"the CHIC ({N_UND_CHIC}) is in the list of active undulators: {n_unds}, and will be ignored/removed") + log.warning(f"the CHIC ({N_UND_CHIC}) is in the list of active undulators: {n_unds}, and will be ignored/removed", stacklevel=3) n_unds.remove(N_UND_CHIC) if n_und_ref not in n_unds: @@ -480,7 +480,15 @@ class Phases: def get_machine_n_und_ref(): - res = PVEnumAdjustable("SATUN:REF-UND").get() + n_tries = 3 + for i in range(n_tries): + res = PVEnumAdjustable("SATUN:REF-UND", internal=True).get() + if res is not None: + break + print(f"try {i+1}/{n_tries}: got None instead of reference undulator number") + sleep(0.1) + if res is None: + raise ValueError(f"got None instead of reference undulator number {n_tries} times") if not res.startswith("SATUN"): return None n = len("SATUN")