fix more threading issues; add users metric

This commit is contained in:
Jakob Ketterl 2019-09-18 15:40:23 +02:00
parent 6f983ccb6b
commit 30512e347a
3 changed files with 19 additions and 8 deletions

View File

@ -1,3 +1,5 @@
import threading
class Metric(object):
def getValue(self):
return 0
@ -24,9 +26,11 @@ class DirectMetric(Metric):
class Metrics(object):
sharedInstance = None
creationLock = threading.Lock()
@staticmethod
def getSharedInstance():
with Metrics.creationLock:
if Metrics.sharedInstance is None:
Metrics.sharedInstance = Metrics()
return Metrics.sharedInstance

View File

@ -4,6 +4,7 @@ from owrx.feature import FeatureDetector, UnknownFeatureException
from owrx.meta import MetaParser
from owrx.wsjt import WsjtParser
from owrx.aprs import AprsParser
from owrx.metrics import Metrics, DirectMetric
import threading
import csdr
import time
@ -698,15 +699,18 @@ class TooManyClientsException(Exception):
class ClientRegistry(object):
sharedInstance = None
creationLock = threading.Lock()
@staticmethod
def getSharedInstance():
with ClientRegistry.creationLock:
if ClientRegistry.sharedInstance is None:
ClientRegistry.sharedInstance = ClientRegistry()
return ClientRegistry.sharedInstance
def __init__(self):
self.clients = []
Metrics.getSharedInstance().addMetric("openwebrx.users", DirectMetric(self.clientCount))
super().__init__()
def broadcast(self):

View File

@ -38,9 +38,11 @@ class WsjtQueueWorker(threading.Thread):
class WsjtQueue(Queue):
sharedInstance = None
creationLock = threading.Lock()
@staticmethod
def getSharedInstance():
with WsjtQueue.creationLock:
if WsjtQueue.sharedInstance is None:
pm = PropertyManager.getSharedInstance()
WsjtQueue.sharedInstance = WsjtQueue(maxsize=pm["wsjt_queue_length"], workers=pm["wsjt_queue_workers"])
@ -125,6 +127,7 @@ class WsjtChopper(threading.Thread):
def _scheduleNextSwitch(self):
with self.schedulerLock:
if self.doRun:
self.scheduler.enterabs(self.getNextDecodingTime(), 1, self.switchFiles)
def switchFiles(self):