Skip to content

Commit

Permalink
Make sure we close the connection to the thermistors
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Sep 17, 2024
1 parent 924db0e commit 87ff15d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Next version

### 🔧 Fixed

* Make sure we close the connection to the thermistors.


## 0.3.8 - September 16, 2024

### 🚀 New
Expand Down
20 changes: 13 additions & 7 deletions src/lvmopstools/devices/thermistors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 87ff15d

Please sign in to comment.