From 76d275db9c8968ce5bd9b52e52fa39c9002aaa86 Mon Sep 17 00:00:00 2001 From: Hemna Date: Sat, 23 Nov 2024 09:13:35 -0500 Subject: [PATCH] Added pause_all, unpause_all in threadlist This patch adds methods for pausing and unpausing all threads in the APRSDThreadList. --- aprsd/threads/aprsd.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/aprsd/threads/aprsd.py b/aprsd/threads/aprsd.py index 8dd3eec..9176bd7 100644 --- a/aprsd/threads/aprsd.py +++ b/aprsd/threads/aprsd.py @@ -40,6 +40,7 @@ class APRSDThread(threading.Thread, metaclass=abc.ABCMeta): self._pause = False def stop(self): + LOG.debug(f"Stopping thread '{self.name}'") self.thread_stop = True @abc.abstractmethod @@ -119,6 +120,24 @@ class APRSDThreadList: LOG.info(F"{th.name} packet {th.packet}") th.stop() + @wrapt.synchronized + def pause_all(self): + """Iterate over all threads and pause them.""" + for th in self.threads_list: + LOG.info(f"Pausing Thread {th.name}") + if hasattr(th, "packet"): + LOG.info(F"{th.name} packet {th.packet}") + th.pause() + + @wrapt.synchronized + def unpause_all(self): + """Iterate over all threads and resume them.""" + for th in self.threads_list: + LOG.info(f"Resuming Thread {th.name}") + if hasattr(th, "packet"): + LOG.info(F"{th.name} packet {th.packet}") + th.unpause() + @wrapt.synchronized(lock) def info(self): """Go through all the threads and collect info about each."""