Skip to main content
Source: src/cwsandbox/init.py:121
wait(waitables: Sequence[Waitable], num_returns: int | None = None, timeout: float | None = None) -> tuple[list[Waitable], list[Waitable]]
Wait for waitables to complete, and return a (done, pending) tuple. Each waitable type has a natural “wait for” behavior:
  • Sandbox: waits until the status is RUNNING.
  • OperationRef: waits until the operation completes.
  • Process: waits until the process completes.
Parameters
  • waitables (Sequence[Waitable]): A sequence of Sandbox, OperationRef, or Process objects.
  • num_returns (int | None): If specified, returns after this many waitables complete. If None, waits for all to complete.
  • timeout (float | None): The maximum number of seconds to wait. If None, waits indefinitely.
Returns
  • tuple[list[Waitable], list[Waitable]]: A tuple of (done, pending) lists containing the original waitable objects.
Raises
  • ValueError: If num_returns is less than 1.
Examples Wait for all sandboxes to be running:
sandboxes = [Sandbox.run(...) for _ in range(5)]
done, pending = cwsandbox.wait(sandboxes)
Wait for the first two operations to complete:
refs = [sb.read_file(f) for f in files]
done, pending = cwsandbox.wait(refs, num_returns=2)
Wait with a timeout:
done, pending = cwsandbox.wait(procs, timeout=30.0)
Last modified on May 29, 2026