> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreweave.com/llms.txt
> Use this file to discover all available pages before exploring further.

# wait

> waitable の完了を待機し、(done, pending) を返します。

ソース: [src/cwsandbox/**init**.py:176](https://github.com/coreweave/cwsandbox-client/blob/v1.14.2/src/cwsandbox/__init__.py#L176)

```python theme={"system"}
wait(waitables: Sequence[Waitable], num_returns: int | None = None, timeout: float | None = None) -> tuple[list[Waitable], list[Waitable]]
```

waitable の完了を待機し、(done, pending) を返します。

各 waitable タイプには、それぞれ固有の「待機」動作があります。

* Sandbox: RUNNING ステータスになるまで待機します

* OperationRef: 操作が完了するまで待機します

* Process: プロセスが完了するまで待機します
  **パラメーター**

* `waitables` (`Sequence[Waitable]`): Sandbox、OperationRef、または Process オブジェクトのシーケンス。

* `num_returns` (`int | None`): 指定した場合、指定した数が完了した時点で返します。None の場合は、すべてが完了するまで待機します。

* `timeout` (`float | None`): 待機する最大秒数。None の場合は無期限に待機します。

**戻り値**

* `tuple[list[Waitable], list[Waitable]]`: 元の waitable オブジェクトを格納した (done, pending) リストのタプル。

**送出される例外**

* `ValueError`: num\_returns が 1 未満の場合。

**サンプル**

すべてのサンドボックスが実行中になるまで待機します。

```python theme={"system"}
sandboxes = [Sandbox.run(...) for _ in range(5)]
done, pending = cwsandbox.wait(sandboxes)
```

最初の 2 つの操作が完了するまで待機します。

```python theme={"system"}
refs = [sb.read_file(f) for f in files]
done, pending = cwsandbox.wait(refs, num_returns=2)
```

タイムアウトを指定して待機します:

```python theme={"system"}
done, pending = cwsandbox.wait(procs, timeout=30.0)
```
