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.
This commit is contained in:
Hemna 2023-07-20 14:44:46 -04:00
parent fa452cc773
commit d3a93b735d
4 changed files with 17 additions and 3 deletions

View File

@ -39,7 +39,7 @@ jobs:
uses: docker/build-push-action@v3 uses: docker/build-push-action@v3
with: with:
context: "{{defaultContext}}:docker" context: "{{defaultContext}}:docker"
platforms: linux/amd64 platforms: linux/amd64,linux/arm64
file: ./Dockerfile file: ./Dockerfile
build-args: | build-args: |
VERSION=${{ inputs.aprsd_version }} VERSION=${{ inputs.aprsd_version }}

View File

@ -62,6 +62,8 @@ class Client:
"""Call this to force a rebuild/reconnect.""" """Call this to force a rebuild/reconnect."""
if self._client: if self._client:
del self._client del self._client
else:
LOG.warning("Client not initialized, nothing to reset.")
@abc.abstractmethod @abc.abstractmethod
def setup_connection(self): def setup_connection(self):

View File

@ -1,4 +1,5 @@
import abc import abc
import datetime
import logging import logging
import threading import threading
@ -50,6 +51,7 @@ class APRSDThread(threading.Thread, metaclass=abc.ABCMeta):
super().__init__(name=name) super().__init__(name=name)
self.thread_stop = False self.thread_stop = False
APRSDThreadList().add(self) APRSDThreadList().add(self)
self._last_loop = datetime.datetime.now()
def _should_quit(self): def _should_quit(self):
""" see if we have a quit message from the global queue.""" """ 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()}>" out = f"Thread <{self.__class__.__name__}({self.name}) Alive? {self.is_alive()}>"
return out return out
def loop_age(self):
"""How old is the last loop call?"""
return datetime.datetime.now() - self._last_loop
def run(self): def run(self):
LOG.debug("Starting") LOG.debug("Starting")
while not self._should_quit(): while not self._should_quit():
can_loop = self.loop() can_loop = self.loop()
self._last_loop = datetime.datetime.now()
if not can_loop: if not can_loop:
self.stop() self.stop()
self._cleanup() self._cleanup()

View File

@ -68,8 +68,13 @@ class KeepAliveThread(APRSDThread):
thread_info = {} thread_info = {}
for thread in thread_list.threads_list: for thread in thread_list.threads_list:
alive = thread.is_alive() alive = thread.is_alive()
thread_out.append(f"{thread.__class__.__name__}:{alive}") age = thread.loop_age()
thread_info[thread.__class__.__name__] = alive 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: if not alive:
LOG.error(f"Thread {thread}") LOG.error(f"Thread {thread}")
LOG.info(",".join(thread_out)) LOG.info(",".join(thread_out))