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 711be9f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
1 change: 1 addition & 0 deletions ophyd/areadetector/filestore_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class MyDetector(PerkinElmerDetector, SingleTrigger): # for example
det = MyDetector(...)
"""

import logging
import os
import uuid
Expand Down
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
1 change: 1 addition & 0 deletions ophyd/tests/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""PV names for tests"""

import os

epics_base = os.environ.get("EPICS_BASE", "/usr/lib/epics")
Expand Down
5 changes: 3 additions & 2 deletions ophyd/tests/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def test_signal_another_call_to_set_in_progress():
sig = Signal(name="sig", value=1)
sig.wait_for_connection()

st1 = sig.set(28, settle_time=.2)
st1 = sig.set(28, settle_time=0.2)
# trap the RuntimeError when "Another set() call " ...
with pytest.raises(RuntimeError):
# TODO: verify the message text startswith?
Expand All @@ -753,7 +753,7 @@ def test_signal_clear_set():
sig = Signal(name="sig", value=1)
sig.wait_for_connection()

st1 = sig.set(28, settle_time=.2)
st1 = sig.set(28, settle_time=0.2)
with pytest.raises(RuntimeError):
assert not st1.done
sig.set(-1)
Expand All @@ -771,6 +771,7 @@ def test_signal_clear_set():
def test_epicssignal_abandonedset():
class BrokenPutSignal(Signal):
"""put(value) ends with same ._readback value as before."""

def put(self, value, **kwargs):
previous_value = self._readback
super().put(value, **kwargs)
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 711be9f

Please sign in to comment.