Skip to content
Snippets Groups Projects
Commit adf0f3c5 authored by David Hammer's avatar David Hammer
Browse files

Move expensive buffer changes to background to avoid timeouts

parent 1a655dcc
No related branches found
No related tags found
1 merge request!12Snapshot: field test deployed version as of end of run 202201
......@@ -709,8 +709,7 @@ class BaseCorrection(PythonDevice):
update = self._prereconfigure_update_hash
if update.has("frameFilter"):
with self._buffer_lock:
self._update_frame_filter()
self._lock_and_update_in_background(self._update_frame_filter)
elif any(
update.has(shape_param)
for shape_param in (
......@@ -721,11 +720,17 @@ class BaseCorrection(PythonDevice):
"frameFilter",
)
):
with self._buffer_lock:
self._update_buffers()
self._lock_and_update_in_background(self._update_buffers)
# TODO: only call this if they are changed (is cheap, though)
self._update_correction_flags()
def _lock_and_update_in_background(self, method):
# TODO: securely handle errors (postReconfigure may succeed and device state not)
def runner():
with self._buffer_lock, utils.StateContext(self, State.CHANGING):
method()
threading.Thread(target=runner, daemon=True).start()
def loadMostRecentConstants(self):
self.flush_constants()
self.calcat_friend.flush_constants()
......
......@@ -279,6 +279,25 @@ class Stopwatch:
return f"{self.name}: {self.elapsed():.3f} s"
class StateContext:
"""What if device state was a stack?"""
def __init__(self, device, new_state, revert_to=None):
self.device = device
if revert_to is None:
revert_to = device.get("state")
self.revert_to = revert_to
self.new_state = new_state
def __enter__(self):
if self.new_state is not self.revert_to:
self.device.updateState(self.new_state)
def __exit__(self, t, v, tb):
if self.new_state is not self.revert_to:
self.device.updateState(self.revert_to)
class TrainRatioTracker:
"""Measure how many percent of recent train IDs (from contiguous set) were seen
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment