From: Benjamin Braatz Date: Thu, 31 Mar 2022 03:20:05 +0000 (+0200) Subject: Catch ConnectionRefusedError and handle no connection. X-Git-Url: http://git.graph-it.com/?a=commitdiff_plain;h=8c70b19a0c2d3e631acc0fc8f9fbf70cf17df5fe;p=graphit%2Fcontrolpi-graph.git Catch ConnectionRefusedError and handle no connection. --- diff --git a/controlpi_plugins/graph.py b/controlpi_plugins/graph.py index e2b77ab..7dbf095 100644 --- a/controlpi_plugins/graph.py +++ b/controlpi_plugins/graph.py @@ -62,46 +62,58 @@ class Graph(BasePlugin): self._messages.append(message) async def _open(self) -> None: - (reader, writer) = await asyncio.open_connection(self._host, - self._port, - ssl=self._ssl_ctx) - self._reader = reader - self._writer = writer - # Read banner: - banner_size_bytes = await self._reader.readexactly(4) - banner_size_int = struct.unpack(' Any: - # Build request: - self._call_id += 1 - request = {'jsonrpc': '2.0', 'method': method, - 'params': params, 'id': self._call_id} - message = msgpack.packb(request) - size_bytes = struct.pack(' None: - # Close connection: - self._writer.close() + if self._writer: + # Close connection: + self._writer.close() + self._reader = None + self._writer = None async def run(self) -> None: """Get coroot instance for name and send connection opened event."""