Available languages: [Python](https://databento.com/docs/api-live/client/wait-for-close.python.md) · [C++](https://databento.com/docs/api-live/client/wait-for-close.cpp.md) · [Rust](https://databento.com/docs/api-live/client/wait-for-close.rust.md) · [Raw](https://databento.com/docs/api-live/client/wait-for-close.raw.md)

Source: https://databento.com/docs/api-live/client/wait-for-close


### Live.wait_for_close

Wait until the session closes or a timeout is reached.
A session will close when the remote gateway disconnects, or after [Live.stop](https://databento.com/docs/api-live/client/terminate.md) or [Live.terminate](https://databento.com/docs/api-live/client/terminate.md) are called.
In the event the connection is closed unexpectedly, a `BentoError` will be raised.

If a `timeout` is specified, [Live.terminate](https://databento.com/docs/api-live/client/terminate.md) will be called when the timeout is reached.

When this method unblocks, the session is guaranteed to be closed.

#### API method

```python
Live.wait_for_close(
    timeout: float | None = None,
) -> None
```

> **Info**
>
> This method is a [coroutine](https://docs.python.org/3/library/asyncio-task.html#coroutines) and must be used with an [await](https://docs.python.org/3/reference/expressions.html#await) expression.

#### Parameters

| Parameter | Type | Required | Description |
| `timeout` | float | optional | A duration in seconds to wait for the session to close. If `None`, wait forever. |

#### Example usage

```python
import databento as db

# Create a live client
client = db.Live(key="$YOUR_API_KEY")

# Subscribe to the trades schema for all ES futures
client.subscribe(
    dataset="GLBX.MDP3",
    schema="trades",
    stype_in="parent",
    symbols="ES.FUT",
)

# Start the session
client.start()

# Wait for the session to end
await client.wait_for_close()
```
