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

python
async def interruptible_sleep(seconds: float, check_interval: float, interrupt_fn: Optional[Callable[[], bool]]) -> bool

Parameters

ParamField float

Total sleep duration in seconds

ParamField float

How often to check for interruption (seconds)

ParamField Optional

Function that returns True if sleep should be interrupted

Returns

ResponseField bool

True if completed full sleep, False if interrupted

Usage

python
>>> interrupted = await interruptible_sleep(30.0, interrupt_fn=lambda: agent.is_stopped())

Uses

  • interrupt_fn
  • asyncio.sleep

Source

View on GitHub

praisonaiagents/agent/retry_utils.py at line 70