fix more threading issues; add users metric
This commit is contained in:
parent
6f983ccb6b
commit
30512e347a
@ -1,3 +1,5 @@
|
|||||||
|
import threading
|
||||||
|
|
||||||
class Metric(object):
|
class Metric(object):
|
||||||
def getValue(self):
|
def getValue(self):
|
||||||
return 0
|
return 0
|
||||||
@ -24,11 +26,13 @@ class DirectMetric(Metric):
|
|||||||
|
|
||||||
class Metrics(object):
|
class Metrics(object):
|
||||||
sharedInstance = None
|
sharedInstance = None
|
||||||
|
creationLock = threading.Lock()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getSharedInstance():
|
def getSharedInstance():
|
||||||
if Metrics.sharedInstance is None:
|
with Metrics.creationLock:
|
||||||
Metrics.sharedInstance = Metrics()
|
if Metrics.sharedInstance is None:
|
||||||
|
Metrics.sharedInstance = Metrics()
|
||||||
return Metrics.sharedInstance
|
return Metrics.sharedInstance
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -4,6 +4,7 @@ from owrx.feature import FeatureDetector, UnknownFeatureException
|
|||||||
from owrx.meta import MetaParser
|
from owrx.meta import MetaParser
|
||||||
from owrx.wsjt import WsjtParser
|
from owrx.wsjt import WsjtParser
|
||||||
from owrx.aprs import AprsParser
|
from owrx.aprs import AprsParser
|
||||||
|
from owrx.metrics import Metrics, DirectMetric
|
||||||
import threading
|
import threading
|
||||||
import csdr
|
import csdr
|
||||||
import time
|
import time
|
||||||
@ -698,15 +699,18 @@ class TooManyClientsException(Exception):
|
|||||||
|
|
||||||
class ClientRegistry(object):
|
class ClientRegistry(object):
|
||||||
sharedInstance = None
|
sharedInstance = None
|
||||||
|
creationLock = threading.Lock()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getSharedInstance():
|
def getSharedInstance():
|
||||||
if ClientRegistry.sharedInstance is None:
|
with ClientRegistry.creationLock:
|
||||||
ClientRegistry.sharedInstance = ClientRegistry()
|
if ClientRegistry.sharedInstance is None:
|
||||||
|
ClientRegistry.sharedInstance = ClientRegistry()
|
||||||
return ClientRegistry.sharedInstance
|
return ClientRegistry.sharedInstance
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.clients = []
|
self.clients = []
|
||||||
|
Metrics.getSharedInstance().addMetric("openwebrx.users", DirectMetric(self.clientCount))
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def broadcast(self):
|
def broadcast(self):
|
||||||
|
11
owrx/wsjt.py
11
owrx/wsjt.py
@ -38,12 +38,14 @@ class WsjtQueueWorker(threading.Thread):
|
|||||||
|
|
||||||
class WsjtQueue(Queue):
|
class WsjtQueue(Queue):
|
||||||
sharedInstance = None
|
sharedInstance = None
|
||||||
|
creationLock = threading.Lock()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getSharedInstance():
|
def getSharedInstance():
|
||||||
if WsjtQueue.sharedInstance is None:
|
with WsjtQueue.creationLock:
|
||||||
pm = PropertyManager.getSharedInstance()
|
if WsjtQueue.sharedInstance is None:
|
||||||
WsjtQueue.sharedInstance = WsjtQueue(maxsize=pm["wsjt_queue_length"], workers=pm["wsjt_queue_workers"])
|
pm = PropertyManager.getSharedInstance()
|
||||||
|
WsjtQueue.sharedInstance = WsjtQueue(maxsize=pm["wsjt_queue_length"], workers=pm["wsjt_queue_workers"])
|
||||||
return WsjtQueue.sharedInstance
|
return WsjtQueue.sharedInstance
|
||||||
|
|
||||||
def __init__(self, maxsize, workers):
|
def __init__(self, maxsize, workers):
|
||||||
@ -125,7 +127,8 @@ class WsjtChopper(threading.Thread):
|
|||||||
|
|
||||||
def _scheduleNextSwitch(self):
|
def _scheduleNextSwitch(self):
|
||||||
with self.schedulerLock:
|
with self.schedulerLock:
|
||||||
self.scheduler.enterabs(self.getNextDecodingTime(), 1, self.switchFiles)
|
if self.doRun:
|
||||||
|
self.scheduler.enterabs(self.getNextDecodingTime(), 1, self.switchFiles)
|
||||||
|
|
||||||
def switchFiles(self):
|
def switchFiles(self):
|
||||||
self.switchingLock.acquire()
|
self.switchingLock.acquire()
|
||||||
|
Loading…
Reference in New Issue
Block a user