StandaloneIO: Modules with above average intervals are refreshed in their own threads. This should prevent freezing of the bar caused by running all modules.
This commit is contained in:
parent
ba01a7af44
commit
8cca39bb1a
@ -54,6 +54,7 @@ class StandaloneIO(IOHandler):
|
|||||||
|
|
||||||
refresh_cond = Condition()
|
refresh_cond = Condition()
|
||||||
modules = []
|
modules = []
|
||||||
|
treshold_interval = 20.0
|
||||||
|
|
||||||
n = -1
|
n = -1
|
||||||
proto = [
|
proto = [
|
||||||
@ -75,6 +76,7 @@ class StandaloneIO(IOHandler):
|
|||||||
StandaloneIO.modules = modules
|
StandaloneIO.modules = modules
|
||||||
|
|
||||||
def read(self):
|
def read(self):
|
||||||
|
StandaloneIO.compute_treshold_interval()
|
||||||
StandaloneIO.refresh_cond.acquire()
|
StandaloneIO.refresh_cond.acquire()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@ -91,6 +93,11 @@ class StandaloneIO(IOHandler):
|
|||||||
|
|
||||||
return self.proto[min(self.n, len(self.proto) - 1)]
|
return self.proto[min(self.n, len(self.proto) - 1)]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def compute_treshold_interval(cls):
|
||||||
|
intervals = [m.interval for m in cls.modules if hasattr(m, "interval")]
|
||||||
|
cls.treshold_interval = round(sum(intervals) / len(intervals))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def async_refresh(cls):
|
def async_refresh(cls):
|
||||||
cls.refresh_cond.acquire()
|
cls.refresh_cond.acquire()
|
||||||
@ -99,10 +106,21 @@ class StandaloneIO(IOHandler):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def refresh_signal_handler(signo, frame):
|
def refresh_signal_handler(signo, frame):
|
||||||
if signo == signal.SIGUSR1:
|
if signo != signal.SIGUSR1:
|
||||||
for module in StandaloneIO.modules:
|
return
|
||||||
|
|
||||||
|
threads = []
|
||||||
|
for module in StandaloneIO.modules:
|
||||||
|
if hasattr(module, "interval"):
|
||||||
|
if module.interval > StandaloneIO.treshold_interval:
|
||||||
|
thread = Thread(target=module.run)
|
||||||
|
thread.start()
|
||||||
|
else:
|
||||||
|
module.run()
|
||||||
|
else:
|
||||||
module.run()
|
module.run()
|
||||||
StandaloneIO.async_refresh()
|
|
||||||
|
StandaloneIO.async_refresh()
|
||||||
|
|
||||||
|
|
||||||
class JSONIO:
|
class JSONIO:
|
||||||
|
Loading…
Reference in New Issue
Block a user