From d3a93b735deb222d9a2c27015a413973c810f4d0 Mon Sep 17 00:00:00 2001 From: Hemna Date: Thu, 20 Jul 2023 14:44:46 -0400 Subject: [PATCH] Added timing after each thread loop This is to help keep track of which non-blocking threads are still alive. The RPC Server thread blocks, so the time will always increase. --- .github/workflows/release_build.yml | 2 +- aprsd/client.py | 2 ++ aprsd/threads/aprsd.py | 7 +++++++ aprsd/threads/keep_alive.py | 9 +++++++-- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release_build.yml b/.github/workflows/release_build.yml index 70e5c93..a3838cf 100644 --- a/.github/workflows/release_build.yml +++ b/.github/workflows/release_build.yml @@ -39,7 +39,7 @@ jobs: uses: docker/build-push-action@v3 with: context: "{{defaultContext}}:docker" - platforms: linux/amd64 + platforms: linux/amd64,linux/arm64 file: ./Dockerfile build-args: | VERSION=${{ inputs.aprsd_version }} diff --git a/aprsd/client.py b/aprsd/client.py index 08df034..f110236 100644 --- a/aprsd/client.py +++ b/aprsd/client.py @@ -62,6 +62,8 @@ class Client: """Call this to force a rebuild/reconnect.""" if self._client: del self._client + else: + LOG.warning("Client not initialized, nothing to reset.") @abc.abstractmethod def setup_connection(self): diff --git a/aprsd/threads/aprsd.py b/aprsd/threads/aprsd.py index a6f7446..51d7960 100644 --- a/aprsd/threads/aprsd.py +++ b/aprsd/threads/aprsd.py @@ -1,4 +1,5 @@ import abc +import datetime import logging import threading @@ -50,6 +51,7 @@ class APRSDThread(threading.Thread, metaclass=abc.ABCMeta): super().__init__(name=name) self.thread_stop = False APRSDThreadList().add(self) + self._last_loop = datetime.datetime.now() def _should_quit(self): """ see if we have a quit message from the global queue.""" @@ -70,10 +72,15 @@ class APRSDThread(threading.Thread, metaclass=abc.ABCMeta): out = f"Thread <{self.__class__.__name__}({self.name}) Alive? {self.is_alive()}>" return out + def loop_age(self): + """How old is the last loop call?""" + return datetime.datetime.now() - self._last_loop + def run(self): LOG.debug("Starting") while not self._should_quit(): can_loop = self.loop() + self._last_loop = datetime.datetime.now() if not can_loop: self.stop() self._cleanup() diff --git a/aprsd/threads/keep_alive.py b/aprsd/threads/keep_alive.py index 0aae05c..9ea3282 100644 --- a/aprsd/threads/keep_alive.py +++ b/aprsd/threads/keep_alive.py @@ -68,8 +68,13 @@ class KeepAliveThread(APRSDThread): thread_info = {} for thread in thread_list.threads_list: alive = thread.is_alive() - thread_out.append(f"{thread.__class__.__name__}:{alive}") - thread_info[thread.__class__.__name__] = alive + age = thread.loop_age() + key = thread.__class__.__name__ + thread_out.append(f"{key}:{alive}:{age}") + if key not in thread_info: + thread_info[key] = {} + thread_info[key]["alive"] = alive + thread_info[key]["age"] = age if not alive: LOG.error(f"Thread {thread}") LOG.info(",".join(thread_out))