i3pystatus
i3pystatus copied to clipboard
When the interval of mem and shell is the same, the module registered later than the other doesn't appear for the first interval.
test1.py
from i3pystatus import Status
status = Status()
status.register("mem", interval=2)
status.register("shell", command="/bin/date", interval=2)
status.run()
$ python test1.py
{"version": 1, "click_events": true}
[
[{"full_text": "29654.1 MiB", "markup": "none", "instance": "139732622327648", "name": "i3pystatus.mem.Mem", "color": "#00FF00"}]
,[{"full_text": "29654.1 MiB", "markup": "none", "instance": "139732622327648", "name": "i3pystatus.mem.Mem", "color": "#00FF00"}]
,[{"full_text": "Tue Apr 24 10:29:01 KST 2018", "instance": "139732633475056", "name": "i3pystatus.shell.Shell", "markup": "none"}, {"full_text": "29654.1 MiB", "markup": "none", "instance": "139732622327648", "name": "i3pystatus.mem.Mem", "color": "#00FF00"}]
test2.py
from i3pystatus import Status
status = Status()
status.register("mem", interval=3)
status.register("shell", command="/bin/date", interval=2)
status.run()
$ python test2.py
{"click_events": true, "version": 1}
[
[{"name": "i3pystatus.shell.Shell", "instance": "139693688709976", "full_text": "Tue Apr 24 10:30:21 KST 2018", "markup": "none"}, {"color": "#00FF00", "name": "i3pystatus.mem.Mem", "instance": "139693691485936", "full_text": "29636.5 MiB", "markup": "none"}]
,[{"name": "i3pystatus.shell.Shell", "instance": "139693688709976", "full_text": "Tue Apr 24 10:30:21 KST 2018", "markup": "none"}, {"color": "#00FF00", "name": "i3pystatus.mem.Mem", "instance": "139693691485936", "full_text": "29636.5 MiB", "markup": "none"}]
Observation
When the interval of mem and shell is the same, if mem comes first, shell doesn't appear for the first interval. If shell comes first, mem doesn't appear for the first interval.
Hi. I know nothing, but this seems to work okay.
diff --git a/i3pystatus/core/io.py b/i3pystatus/core/io.py
index 7ca6019..0b43bd0 100644
--- a/i3pystatus/core/io.py
+++ b/i3pystatus/core/io.py
@@ -171,9 +171,9 @@ class StandaloneIO(IOHandler):
return
self.stopped = not self.stopped
if self.stopped:
- [m.suspend() for m in IntervalModule.managers.values()]
+ [m.suspend() for m in IntervalModule.managers]
else:
- [m.resume() for m in IntervalModule.managers.values()]
+ [m.resume() for m in IntervalModule.managers]
class JSONIO:
diff --git a/i3pystatus/core/modules.py b/i3pystatus/core/modules.py
index 31dc377..7d89e1a 100644
--- a/i3pystatus/core/modules.py
+++ b/i3pystatus/core/modules.py
@@ -281,17 +281,15 @@ class IntervalModule(Module):
("interval", "interval in seconds between module updates"),
)
interval = 5 # seconds
- managers = {}
+ managers = []
+
def registered(self, status_handler):
super(IntervalModule, self).registered(status_handler)
- if self.interval in IntervalModule.managers:
- IntervalModule.managers[self.interval].append(self)
- else:
- am = Manager(self.interval)
- am.append(self)
- IntervalModule.managers[self.interval] = am
- am.start()
+ am = Manager(self.interval)
+ am.append(self)
+ IntervalModule.managers.append(am)
+ am.start()
def __call__(self):
self.run()
I think the issue might be somewhere around here. I am not familiar with Threads. If modules with identical intervals are used (i.e. 2) then we will have managers = {'2': Manager} with workloads appended (diff below) instead of appending Threads (diff above)... and when we resume/suspend threads, we loop one Thread w/ workloads. Is that it?
diff --git a/i3pystatus/core/threading.py b/i3pystatus/core/threading.py
index 6e4a475..85dfc29 100644
--- a/i3pystatus/core/threading.py
+++ b/i3pystatus/core/threading.py
@@ -162,7 +162,7 @@ class Manager:
self.threads.append(thread)
def append(self, workload):
+ # possibly no resume/suspend causes issue at startup?
self.threads[0].append(self.wrap(workload))
def start(self):
for thread in self.threads: