From c8c8e2226f06adfc7f89fe82358e66203c5a4f6e Mon Sep 17 00:00:00 2001 From: enkore Date: Sun, 10 Mar 2013 02:11:58 +0100 Subject: [PATCH] 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!?) --- i3pystatus/__init__.py | 7 ++++++- i3pystatus/core/modules.py | 9 +++++++++ i3pystatus/core/threads.py | 5 ++++- setup.py | 2 +- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/i3pystatus/__init__.py b/i3pystatus/__init__.py index 806ff8a..dc7a641 100644 --- a/i3pystatus/__init__.py +++ b/i3pystatus/__init__.py @@ -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) diff --git a/i3pystatus/core/modules.py b/i3pystatus/core/modules.py index eb094c0..443d115 100644 --- a/i3pystatus/core/modules.py +++ b/i3pystatus/core/modules.py @@ -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, +) diff --git a/i3pystatus/core/threads.py b/i3pystatus/core/threads.py index 1efa635..4392bcc 100644 --- a/i3pystatus/core/threads.py +++ b/i3pystatus/core/threads.py @@ -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() diff --git a/setup.py b/setup.py index 862ad8b..48e7b8b 100755 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup setup(name="i3pystatus", - version="3.9", + version="3.10", description="Like i3status, this generates status line for i3bar / i3wm", url="http://github.com/enkore/i3pystatus", license="MIT",