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
with:
context: "{{defaultContext}}:docker"
platforms: linux/amd64
platforms: linux/amd64,linux/arm64
file: ./Dockerfile
build-args: |
VERSION=${{ inputs.aprsd_version }}

View File

@ -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):

View File

@ -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()

View File

@ -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))