summaryrefslogtreecommitdiffstats
path: root/py3status
diff options
context:
space:
mode:
authorUltrabug <ultrabug@gentoo.org>2015-02-05 00:34:49 +0100
committerUltrabug <ultrabug@gentoo.org>2015-02-05 00:34:49 +0100
commit7e3cccbf69c3a2c2bf1dd7d3cee82404a670dbf0 (patch)
tree3bdc56fc9e9c3ecd05a587f52a0f7773fd5e27fd /py3status
parent7b2f03250e065fc4cd59f53aeb72825c82896d5a (diff)
make the main loop iterate fast to catch any module or i3status update almost instantly while keeping the configured interval for modules refresh rate
Diffstat (limited to 'py3status')
-rwxr-xr-xpy3status/__init__.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/py3status/__init__.py b/py3status/__init__.py
index 9abb0d5..5394f13 100755
--- a/py3status/__init__.py
+++ b/py3status/__init__.py
@@ -1405,6 +1405,9 @@ class Py3statusWrapper():
signal(SIGUSR1, self.sig_handler)
signal(SIGTERM, self.terminate)
+ # initialize an empty json list output
+ previous_json_list = []
+
# main loop
while True:
try:
@@ -1456,14 +1459,18 @@ class Py3statusWrapper():
# old style ordering
json_list = self.get_modules_output(json_list)
- # dump the line to stdout
- print_line('{}{}'.format(prefix, dumps(json_list)))
+ # dump the line to stdout on change
+ if json_list != previous_json_list:
+ print_line('{}{}'.format(prefix, dumps(json_list)))
# update i3status output
self.i3status_thread.update_json_list()
- # sleep a bit before doing this again
- sleep(self.config['interval'])
+ # remember the last json list output
+ previous_json_list = json_list
+
+ # sleep a bit before doing this again to avoid killing the CPU
+ sleep(0.1)
except UserWarning:
# SIGUSR1 was received, we also force i3status to refresh by
# sending it a SIGUSR1 as well then we refresh the bar asap