maple.utils.timeout.run_with_timeout
- maple.utils.timeout.run_with_timeout(func: Callable[[], T], timeout: float, operation: str = 'Operation', default: T | None = None, raise_on_timeout: bool = True) T
Run a function with a timeout.
- Parameters:
func – Callable to execute
timeout – Timeout in seconds
operation – Name of operation for error messages
default – Default value to return on timeout (if raise_on_timeout=False)
raise_on_timeout – If True, raise TimeoutError on timeout
- Returns:
Result of func or default on timeout
- Example:
- action = run_with_timeout(
lambda: policy.act(obs), timeout=30.0, operation=”Policy inference”
)