From 87ff15d3e6bbffb5600ff6ff32e84c74eb07b3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20S=C3=A1nchez-Gallego?= Date: Tue, 17 Sep 2024 21:01:57 +0000 Subject: [PATCH] Make sure we close the connection to the thermistors --- CHANGELOG.md | 7 +++++++ src/lvmopstools/devices/thermistors.py | 20 +++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d615e3..c607364 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## Next version + +### 🔧 Fixed + +* Make sure we close the connection to the thermistors. + + ## 0.3.8 - September 16, 2024 ### 🚀 New diff --git a/src/lvmopstools/devices/thermistors.py b/src/lvmopstools/devices/thermistors.py index 2510202..851a964 100644 --- a/src/lvmopstools/devices/thermistors.py +++ b/src/lvmopstools/devices/thermistors.py @@ -55,13 +55,19 @@ async def read_thermistors(): host = th_config["host"] port = th_config["port"] - socket = await asyncio.wait_for( - asyncudp.create_socket(remote_addr=(host, port)), - timeout=5, - ) - - socket.sendto(b"$016\r\n") - data, _ = await asyncio.wait_for(socket.recvfrom(), timeout=10) + socket: asyncudp.Socket | None = None + + try: + socket = await asyncio.wait_for( + asyncudp.create_socket(remote_addr=(host, port)), + timeout=5, + ) + + socket.sendto(b"$016\r\n") + data, _ = await asyncio.wait_for(socket.recvfrom(), timeout=10) + finally: + if socket: + socket.close() match = re.match(rb"!01([0-9A-F]+)\r", data) if match is None: