Merge branch 'main' into 147-sig-activity-changes

# Conflicts:
#	core/constants.py
#	pyproject.toml
This commit is contained in:
Ian Renton
2026-09-20 09:51:29 +01:00
26 changed files with 93 additions and 44 deletions
+19 -5
View File
@@ -1,7 +1,8 @@
import logging
import re
import socket
from datetime import datetime
from threading import Event, Thread
from threading import Event, Lock, Thread
import pytz
import telnetlib3
@@ -40,6 +41,7 @@ class DXCluster(SpotProvider):
self._LINE_PATTERN_ALLOW_RBN if self._allow_rbn_spots else self._LINE_PATTERN_EXCLUDE_RBN
)
self._telnet = None
self._telnet_lock = Lock()
self._thread = None
self._stop_event = Event()
@@ -49,10 +51,15 @@ class DXCluster(SpotProvider):
def stop(self):
self._stop_event.set()
if self._telnet:
self._telnet.close()
with self._telnet_lock:
if self._telnet:
try:
self._telnet.sock.shutdown(socket.SHUT_RDWR)
except (AttributeError, OSError):
pass
self._telnet.close()
if self._thread:
self._thread.join(timeout=15)
self._thread.join(timeout=5)
if self._thread.is_alive():
logger.warning(f"DX Cluster {self._hostname} worker thread did not exit on time and will be killed.")
@@ -63,7 +70,14 @@ class DXCluster(SpotProvider):
try:
self.status = "Connecting"
logger.info(f"DX Cluster {self._hostname} connecting...")
self._telnet = telnetlib3.Telnet(self._hostname, self._port)
new_telnet = telnetlib3.Telnet(self._hostname, self._port)
with self._telnet_lock:
self._telnet = new_telnet
if self._stop_event.is_set():
# stop() was called while we were connecting, close the connection rather than trying to
# read when we know it won't work
new_telnet.close()
break
self._telnet.read_until(self._login_prompt.encode("latin-1"))
self._telnet.write(f"{self._login_callsign}\n".encode("latin-1"))
connected = True