Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes from NSLS-II SIX for clearer error messages about timeouts #779

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions ophyd/utils/epics_pvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def wrapper(self, *args, **kwargs):
return wrapper


def set_and_wait(signal, val, poll_time=0.01, timeout=10, rtol=None,
def set_and_wait(signal, val, poll_time=0.01, timeout=60, rtol=None,
atol=None):
"""Set a signal to a value and wait until it reads correctly.

Expand All @@ -226,7 +226,8 @@ def set_and_wait(signal, val, poll_time=0.01, timeout=10, rtol=None,
TimeoutError if timeout is exceeded
"""
signal.put(val)
expiration_time = ttime.time() + timeout if timeout is not None else None
start_time = ttime.time()
expiration_time = start_time + timeout if timeout is not None else None
current_value = signal.get()

if atol is None and hasattr(signal, 'tolerance'):
Expand All @@ -252,7 +253,7 @@ def set_and_wait(signal, val, poll_time=0.01, timeout=10, rtol=None,
else:
within_str = ''

while not _compare_maybe_enum(val, current_value, es, atol, rtol):
while not _compare_maybe_enum(val, current_value, es, atol, rtol, timeout, start_time, signal.name):
logger.debug("Waiting for %s to be set from %r to %r%s...",
signal.name, current_value, val, within_str)
ttime.sleep(poll_time)
Expand All @@ -265,15 +266,18 @@ def set_and_wait(signal, val, poll_time=0.01, timeout=10, rtol=None,
(signal, val, timeout, current_value))


def _compare_maybe_enum(a, b, enums, atol, rtol):
def _compare_maybe_enum(a, b, enums, atol, rtol, timeout, start_time, signal_name):
if enums:
# convert enum values to strings if necessary first:
if not isinstance(a, str):
a = enums[a]
if not isinstance(b, str):
b = enums[b]
# then compare the strings
return a == b
ret = a == b
if ret and signal_name == 'rixscam_hdf5_capture':
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, this should be parametrized or removed.

print(f'>>>> Setting "{signal_name}" to {a} took {ttime.time() - start_time:.5f}s (timeout={timeout}s)')
return ret

# if either relative/absolute tolerance is used, use numpy
# to compare:
Expand Down