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:
enkore 2013-03-10 02:11:58 +01:00
parent 375ba3af7b
commit c8c8e2226f
4 changed files with 20 additions and 3 deletions

View File

@ -4,7 +4,7 @@ import sys
import threading import threading
from .core import util, io 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.settings import SettingsBase
from .core.config import ConfigFinder from .core.config import ConfigFinder
@ -43,7 +43,12 @@ class Status:
if module: if module:
module.on_click(j["button"]) module.on_click(j["button"])
def call_start_hooks(self):
for hook in START_HOOKS:
hook()
def run(self): def run(self):
self.call_start_hooks()
for j in io.JSONIO(self.io).read(): for j in io.JSONIO(self.io).read():
for module in self.modules: for module in self.modules:
module.inject(j) module.inject(j)

View File

@ -57,6 +57,11 @@ class IntervalModule(Module):
am.append(self) am.append(self)
IntervalModule.managers[self.interval] = am IntervalModule.managers[self.interval] = am
@classmethod
def _start(cls):
for manager in cls.managers.values():
manager.start()
def __call__(self): def __call__(self):
self.run() self.run()
@ -65,3 +70,7 @@ class IntervalModule(Module):
Do not rely on this being called from the same thread at all times. 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.""" If you need to always have the same thread context, subclass AsyncModule."""
START_HOOKS = (
IntervalModule._start,
)

View File

@ -89,7 +89,6 @@ class AutomagicManager:
initial_thread = Thread(target_interval, [self.wrap(self)]) initial_thread = Thread(target_interval, [self.wrap(self)])
self.threads = [initial_thread] self.threads = [initial_thread]
initial_thread.start()
def __call__(self): def __call__(self):
separate = [] separate = []
@ -126,3 +125,7 @@ class AutomagicManager:
def append(self, workload): def append(self, workload):
self.threads[0].append(self.wrap(workload)) self.threads[0].append(self.wrap(workload))
def start(self):
for thread in self.threads:
thread.start()

View File

@ -3,7 +3,7 @@
from setuptools import setup from setuptools import setup
setup(name="i3pystatus", setup(name="i3pystatus",
version="3.9", version="3.10",
description="Like i3status, this generates status line for i3bar / i3wm", description="Like i3status, this generates status line for i3bar / i3wm",
url="http://github.com/enkore/i3pystatus", url="http://github.com/enkore/i3pystatus",
license="MIT", license="MIT",