delay startup of background services to increase user interface response

This commit is contained in:
Jakob Ketterl 2019-08-03 23:44:56 +02:00
parent 8f7f34c190
commit d1eaab7711

View File

@ -30,12 +30,13 @@ class ServiceHandler(object):
def __init__(self, source): def __init__(self, source):
self.services = [] self.services = []
self.source = source self.source = source
self.startupTimer = None
self.source.addClient(self) self.source.addClient(self)
self.source.getProps().collect("center_freq", "samp_rate").wire(self.onFrequencyChange) self.source.getProps().collect("center_freq", "samp_rate").wire(self.onFrequencyChange)
self.updateServices() self.scheduleServiceStartup()
def onSdrAvailable(self): def onSdrAvailable(self):
self.updateServices() self.scheduleServiceStartup()
def onSdrUnavailable(self): def onSdrUnavailable(self):
self.stopServices() self.stopServices()
@ -54,9 +55,16 @@ class ServiceHandler(object):
service.start() service.start()
def onFrequencyChange(self, key, value): def onFrequencyChange(self, key, value):
self.stopServices()
if not self.source.isAvailable(): if not self.source.isAvailable():
return return
self.updateServices() self.scheduleServiceStartup()
def scheduleServiceStartup(self):
if self.startupTimer:
self.startupTimer.cancel()
self.startupTimer = threading.Timer(10, self.updateServices)
self.startupTimer.start()
def updateServices(self): def updateServices(self):
logger.debug("re-scheduling services due to sdr changes") logger.debug("re-scheduling services due to sdr changes")