Skip to content

close

Close the subscription connection if it is open. Calling close() more than once is safe.

Close the subscription connection, if it is open.

Example
stream = client.subscribe([{"event": "pane.output"}])
with stream:
    print(stream.ack)
stream.close()
Source code in src/herdr_client/sync/client.py
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
def close(self) -> None:
    """Close the subscription connection, if it is open.

    Example:
        ```python
        stream = client.subscribe([{"event": "pane.output"}])
        with stream:
            print(stream.ack)
        stream.close()
        ```
    """
    file, self._file = self._file, None
    if file is not None:
        file.close()
    connection, self._socket = self._socket, None
    if connection is not None:
        connection.close()