mirror of https://github.com/craigerl/aprsd.git
Lock around client reset
We now have multiple places where we call reset in case a network connection fails, so now there is a mutex lock around the reset method.
This commit is contained in:
parent
71d72adf06
commit
50e491bab4
|
@ -1,11 +1,13 @@
|
||||||
import abc
|
import abc
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import aprslib
|
import aprslib
|
||||||
from aprslib.exceptions import LoginError
|
from aprslib.exceptions import LoginError
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
import wrapt
|
||||||
|
|
||||||
from aprsd import exception
|
from aprsd import exception
|
||||||
from aprsd.clients import aprsis, fake, kiss
|
from aprsd.clients import aprsis, fake, kiss
|
||||||
|
@ -28,6 +30,10 @@ factory = None
|
||||||
|
|
||||||
@singleton
|
@singleton
|
||||||
class APRSClientStats:
|
class APRSClientStats:
|
||||||
|
|
||||||
|
lock = threading.Lock()
|
||||||
|
|
||||||
|
@wrapt.synchronized(lock)
|
||||||
def stats(self, serializable=False):
|
def stats(self, serializable=False):
|
||||||
client = factory.create()
|
client = factory.create()
|
||||||
stats = {
|
stats = {
|
||||||
|
@ -58,6 +64,7 @@ class Client:
|
||||||
|
|
||||||
connected = False
|
connected = False
|
||||||
filter = None
|
filter = None
|
||||||
|
lock = threading.Lock()
|
||||||
|
|
||||||
def __new__(cls, *args, **kwargs):
|
def __new__(cls, *args, **kwargs):
|
||||||
"""This magic turns this into a singleton."""
|
"""This magic turns this into a singleton."""
|
||||||
|
@ -97,6 +104,7 @@ class Client:
|
||||||
packet_list.PacketList().tx(packet)
|
packet_list.PacketList().tx(packet)
|
||||||
self.client.send(packet)
|
self.client.send(packet)
|
||||||
|
|
||||||
|
@wrapt.synchronized(lock)
|
||||||
def reset(self):
|
def reset(self):
|
||||||
"""Call this to force a rebuild/reconnect."""
|
"""Call this to force a rebuild/reconnect."""
|
||||||
LOG.info("Resetting client connection.")
|
LOG.info("Resetting client connection.")
|
||||||
|
|
Loading…
Reference in New Issue