mirror of
https://github.com/bec-project/ophyd_devices.git
synced 2026-11-29 04:28:04 +01:00
feat(utils): add NO_TIMEOUT opt-out for the device default timeout
This commit is contained in:
1 parent
9d3aadc40c
commit
a34577a286
1 file changed
+22
-1
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import ctypes
|
||||
import math
|
||||
import operator
|
||||
import threading
|
||||
import traceback
|
||||
@@ -37,11 +38,22 @@ __all__ = [
|
||||
"AndStatus",
|
||||
"DeviceStatus",
|
||||
"MoveStatus",
|
||||
"NO_TIMEOUT",
|
||||
"Status",
|
||||
"StatusBase",
|
||||
"SubscriptionStatus",
|
||||
]
|
||||
|
||||
|
||||
class _NoTimeout:
|
||||
"""Sentinel requesting a status without any timeout, bypassing the device default."""
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return "NO_TIMEOUT"
|
||||
|
||||
|
||||
NO_TIMEOUT = _NoTimeout()
|
||||
|
||||
logger = bec_logger.logger
|
||||
|
||||
set_async_exc = ctypes.pythonapi.PyThreadState_SetAsyncExc
|
||||
@@ -231,8 +243,17 @@ def _get_default_timeout(obj) -> float | None:
|
||||
|
||||
|
||||
def _resolve_timeout(timeout, obj) -> float | None:
|
||||
"""Use an explicit timeout, falling back to the object's default timeout."""
|
||||
"""
|
||||
Use an explicit timeout, falling back to the object's default timeout.
|
||||
|
||||
Pass NO_TIMEOUT (or a non-positive/non-finite value) to explicitly request
|
||||
a status without any timeout, bypassing the device default.
|
||||
"""
|
||||
if timeout is NO_TIMEOUT:
|
||||
return None
|
||||
if timeout is not None:
|
||||
if not math.isfinite(timeout) or timeout <= 0:
|
||||
return None
|
||||
return timeout
|
||||
return _get_default_timeout(obj)
|
||||
|
||||
|
||||
Reference in new issue
Block a user