mirror of https://github.com/craigerl/aprsd.git
Removed unused threading code
This commit is contained in:
parent
123b3ffa81
commit
9fc5356456
|
@ -135,7 +135,7 @@ def listen(
|
||||||
keepalive.start()
|
keepalive.start()
|
||||||
|
|
||||||
LOG.debug("Create APRSDListenThread")
|
LOG.debug("Create APRSDListenThread")
|
||||||
listen_thread = APRSDListenThread(threads.msg_queues, config=config)
|
listen_thread = APRSDListenThread(threads.packet_queue, config=config)
|
||||||
LOG.debug("Start APRSDListenThread")
|
LOG.debug("Start APRSDListenThread")
|
||||||
listen_thread.start()
|
listen_thread.start()
|
||||||
LOG.debug("keepalive Join")
|
LOG.debug("keepalive Join")
|
||||||
|
|
|
@ -80,7 +80,6 @@ class EmailPlugin(plugin.APRSDRegexCommandPluginBase):
|
||||||
def create_threads(self):
|
def create_threads(self):
|
||||||
if self.enabled:
|
if self.enabled:
|
||||||
return APRSDEmailThread(
|
return APRSDEmailThread(
|
||||||
msg_queues=threads.msg_queues,
|
|
||||||
config=self.config,
|
config=self.config,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -502,9 +501,8 @@ def resend_email(config, count, fromcall):
|
||||||
|
|
||||||
|
|
||||||
class APRSDEmailThread(threads.APRSDThread):
|
class APRSDEmailThread(threads.APRSDThread):
|
||||||
def __init__(self, msg_queues, config):
|
def __init__(self, config):
|
||||||
super().__init__("EmailThread")
|
super().__init__("EmailThread")
|
||||||
self.msg_queues = msg_queues
|
|
||||||
self.config = config
|
self.config = config
|
||||||
self.past = datetime.datetime.now()
|
self.past = datetime.datetime.now()
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import abc
|
import abc
|
||||||
import logging
|
import logging
|
||||||
from queue import Queue
|
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import wrapt
|
import wrapt
|
||||||
|
@ -16,7 +15,6 @@ class APRSDThreadList:
|
||||||
|
|
||||||
threads_list = []
|
threads_list = []
|
||||||
lock = threading.Lock()
|
lock = threading.Lock()
|
||||||
global_queue = Queue()
|
|
||||||
|
|
||||||
def __new__(cls, *args, **kwargs):
|
def __new__(cls, *args, **kwargs):
|
||||||
if cls._instance is None:
|
if cls._instance is None:
|
||||||
|
@ -26,7 +24,6 @@ class APRSDThreadList:
|
||||||
|
|
||||||
@wrapt.synchronized(lock)
|
@wrapt.synchronized(lock)
|
||||||
def add(self, thread_obj):
|
def add(self, thread_obj):
|
||||||
thread_obj.set_global_queue(self.global_queue)
|
|
||||||
self.threads_list.append(thread_obj)
|
self.threads_list.append(thread_obj)
|
||||||
|
|
||||||
@wrapt.synchronized(lock)
|
@wrapt.synchronized(lock)
|
||||||
|
@ -35,7 +32,6 @@ class APRSDThreadList:
|
||||||
|
|
||||||
@wrapt.synchronized(lock)
|
@wrapt.synchronized(lock)
|
||||||
def stop_all(self):
|
def stop_all(self):
|
||||||
self.global_queue.put_nowait({"quit": True})
|
|
||||||
"""Iterate over all threads and call stop on them."""
|
"""Iterate over all threads and call stop on them."""
|
||||||
for th in self.threads_list:
|
for th in self.threads_list:
|
||||||
LOG.info(f"Stopping Thread {th.name}")
|
LOG.info(f"Stopping Thread {th.name}")
|
||||||
|
@ -50,30 +46,15 @@ class APRSDThreadList:
|
||||||
|
|
||||||
class APRSDThread(threading.Thread, metaclass=abc.ABCMeta):
|
class APRSDThread(threading.Thread, metaclass=abc.ABCMeta):
|
||||||
|
|
||||||
global_queue = None
|
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
super().__init__(name=name)
|
super().__init__(name=name)
|
||||||
self.thread_stop = False
|
self.thread_stop = False
|
||||||
APRSDThreadList().add(self)
|
APRSDThreadList().add(self)
|
||||||
|
|
||||||
def set_global_queue(self, global_queue):
|
|
||||||
self.global_queue = global_queue
|
|
||||||
|
|
||||||
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."""
|
||||||
if self.thread_stop:
|
if self.thread_stop:
|
||||||
return True
|
return True
|
||||||
if self.global_queue.empty():
|
|
||||||
return False
|
|
||||||
msg = self.global_queue.get(timeout=1)
|
|
||||||
if not msg:
|
|
||||||
return False
|
|
||||||
if "quit" in msg and msg["quit"] is True:
|
|
||||||
# put the message back on the queue for others
|
|
||||||
self.global_queue.put_nowait(msg)
|
|
||||||
self.thread_stop = True
|
|
||||||
return True
|
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.thread_stop = True
|
self.thread_stop = True
|
||||||
|
|
Loading…
Reference in New Issue