Skip to content

events

Yield pushed event envelopes until the server closes the socket. The subscription must already be open, normally through a with block.

Yield pushed event payloads until the server closes the socket.

Raises:

Type Description
RuntimeError

If the subscription has not been opened with with.

Example
with client.subscribe([{"event": "pane.output"}]) as stream:
    for event in stream.events():
        print(event["event"])
Source code in src/herdr_client/sync/client.py
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
def events(self) -> Iterator[EventEnvelope]:
    """Yield pushed event payloads until the server closes the socket.

    Raises:
        RuntimeError: If the subscription has not been opened with ``with``.

    Example:
        ```python
        with client.subscribe([{"event": "pane.output"}]) as stream:
            for event in stream.events():
                print(event["event"])
        ```
    """
    file = self._file
    if file is None or self._socket is None:
        raise RuntimeError("subscription has not been opened")

    while True:
        line = read_line(file)
        if line == b"":
            return
        if line.strip() == b"":
            continue
        yield event_envelope(decode_json(line))