Interruptible Sleep • AI Agent SDK
interruptible_sleep: Sleep with periodic interruption checks.
interruptible_sleep
Async
Function
</div>
This function is defined in the retry_utils module.
Sleep with periodic interruption checks.
Signature
async def interruptible_sleep(seconds: float, check_interval: float, interrupt_fn: Optional[Callable[[], bool]]) -> boolParameters
ParamField
floatTotal sleep duration in seconds
ParamField
floatHow often to check for interruption (seconds)
ParamField
OptionalFunction that returns True if sleep should be interrupted
Returns
ResponseField
boolTrue if completed full sleep, False if interrupted
Usage
>>> interrupted = await interruptible_sleep(30.0, interrupt_fn=lambda: agent.is_stopped())Uses
interrupt_fnasyncio.sleep
Source
View on GitHubpraisonaiagents/agent/retry_utils.py at line 70