Skip to content

Make a DEFAULT_TIMEOUT externally modifiable #1180

@coretl

Description

@coretl

This would be useful in both tests, and as a general "something timed out, just try increasing the timeout a bit and see if it helps".
Need to keep a global reference that can temporarily (via context manager) or permanently (with function call) be set to a new value

Suggestion for implementation:

# core/_util.py
class OverridableTimeout(SupportsFloat):
    def __init__(self, value: float):
        self.value = value
    def set_to(self, value: float) -> ContextManager:
        original_value = self.value
        self.value = value
        @functools.context_manager
        def revert():
            yield
            self.value = original_value
        return revert
    def __float__(self) -> float:
        return self.value

DEFAULT_TIMEOUT = OverridableTimeout(10.0)
         
# test_my_device.py
from ophyd_async.core import DEFAULT_TIMEOUT

with DEFAULT_TIMEOUT.set_to(0.01):
    with pytest.raises(TimeoutError):
        # Somethere this calls a utility function with timeout=DEFAULT_TIMEOUT
        await device.read()

# at runtime
>>> RE(bps.rd(device))
# uh oh it failed
>>> from ophyd_async.core import DEFAULT_TIMEOUT
>>> DEFAULT_TIMEOUT.set_to(20.0)
>>> RE(bps.rd(device))
# yay it worked

Acceptance Criteria

  • Code and tests written
  • Docs page written to show usage in both tests and at runtime

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions