Skip to content

Commit

Permalink
STY: run black over changed code
Browse files Browse the repository at this point in the history
  • Loading branch information
tacaswell committed Oct 16, 2024
1 parent 82dadb2 commit 9f50cfc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
7 changes: 5 additions & 2 deletions ophyd/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Signal(OphydObject):
rtolerance : any, optional
The relative tolerance associated with the value
"""

SUB_VALUE = "value"
SUB_META = "meta"
_default_sub = SUB_VALUE
Expand Down Expand Up @@ -387,7 +388,8 @@ def set_thread():
f"Another set() call is still in progress for {self.name}. "
"If this is due to some transient failure, verify that the "
"device is configured the way you expect, and use clear_set() "
"to ignore and abandon the previous set() operation.")
"to ignore and abandon the previous set() operation."
)

st = Status(self)
self._status = st
Expand All @@ -411,7 +413,8 @@ def clear_set(self):
self._set_thread.join() # Wait for that to take effect.
warnings.warn(
"A previous set() operation is being ignored. Only do this "
"when debugging or recovering from a hardware failure.")
"when debugging or recovering from a hardware failure."
)

@property
def value(self):
Expand Down
36 changes: 27 additions & 9 deletions ophyd/utils/epics_pvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,15 @@ class AbandonedSet(OpException):


def _set_and_wait(
signal, val, poll_time=0.01, timeout=10, rtol=None, atol=None,
*, poison_pill=None, **kwargs
signal,
val,
poll_time=0.01,
timeout=10,
rtol=None,
atol=None,
*,
poison_pill=None,
**kwargs,
):
"""Set a signal to a value and wait until it reads correctly.
Expand Down Expand Up @@ -245,13 +252,18 @@ def _set_and_wait(
"""
signal.put(val, **kwargs)
_wait_for_value(
signal, val, poll_time=poll_time, timeout=timeout, rtol=rtol, atol=atol,
poison_pill=poison_pill
signal,
val,
poll_time=poll_time,
timeout=timeout,
rtol=rtol,
atol=atol,
poison_pill=poison_pill,
)


def _wait_for_value(
signal, val, poll_time=0.01, timeout=10, rtol=None, atol=None, *, poison_pill
signal, val, poll_time=0.01, timeout=10, rtol=None, atol=None, *, poison_pill
):
"""Wait for a signal to match a value.
Expand Down Expand Up @@ -306,18 +318,24 @@ def _wait_for_value(
within_str = ""

while (val is not None and current_value is None) or not _compare_maybe_enum(
val, current_value, enum_strings, atol, rtol
val, current_value, enum_strings, atol, rtol
):
logger.debug("Waiting for %s to be set from %r to %r%s...",
signal.name, current_value, val, within_str)
logger.debug(
"Waiting for %s to be set from %r to %r%s...",
signal.name,
current_value,
val,
within_str,
)
# Sleep.
if poison_pill is None:
ttime.sleep(poll_time)
elif poison_pill.wait(poll_time):
# This set operation has been abandoned.
raise AbandonedSet(
f"The signal {signal} was set to {val} but it does not seem "
"to have finished. We are no longer watching for it.")
"to have finished. We are no longer watching for it."
)
if poll_time < 0.1:
poll_time *= 2 # logarithmic back-off
current_value = signal.get(**get_kwargs)
Expand Down

0 comments on commit 9f50cfc

Please sign in to comment.