Improved UX a bit: all threads are immediately started;
no more slow starting of modules. Although I'm highly unsatisfied with the current implementation (SoC, you hear me!?)
This commit is contained in:
parent
375ba3af7b
commit
c8c8e2226f
@ -4,7 +4,7 @@ import sys
|
||||
import threading
|
||||
|
||||
from .core import util, io
|
||||
from .core.modules import *
|
||||
from .core.modules import Module, AsyncModule, IntervalModule, START_HOOKS
|
||||
from .core.settings import SettingsBase
|
||||
from .core.config import ConfigFinder
|
||||
|
||||
@ -43,7 +43,12 @@ class Status:
|
||||
if module:
|
||||
module.on_click(j["button"])
|
||||
|
||||
def call_start_hooks(self):
|
||||
for hook in START_HOOKS:
|
||||
hook()
|
||||
|
||||
def run(self):
|
||||
self.call_start_hooks()
|
||||
for j in io.JSONIO(self.io).read():
|
||||
for module in self.modules:
|
||||
module.inject(j)
|
||||
|
@ -57,6 +57,11 @@ class IntervalModule(Module):
|
||||
am.append(self)
|
||||
IntervalModule.managers[self.interval] = am
|
||||
|
||||
@classmethod
|
||||
def _start(cls):
|
||||
for manager in cls.managers.values():
|
||||
manager.start()
|
||||
|
||||
def __call__(self):
|
||||
self.run()
|
||||
|
||||
@ -65,3 +70,7 @@ class IntervalModule(Module):
|
||||
|
||||
Do not rely on this being called from the same thread at all times.
|
||||
If you need to always have the same thread context, subclass AsyncModule."""
|
||||
|
||||
START_HOOKS = (
|
||||
IntervalModule._start,
|
||||
)
|
||||
|
@ -89,7 +89,6 @@ class AutomagicManager:
|
||||
|
||||
initial_thread = Thread(target_interval, [self.wrap(self)])
|
||||
self.threads = [initial_thread]
|
||||
initial_thread.start()
|
||||
|
||||
def __call__(self):
|
||||
separate = []
|
||||
@ -126,3 +125,7 @@ class AutomagicManager:
|
||||
|
||||
def append(self, workload):
|
||||
self.threads[0].append(self.wrap(workload))
|
||||
|
||||
def start(self):
|
||||
for thread in self.threads:
|
||||
thread.start()
|
||||
|
Loading…
Reference in New Issue
Block a user