summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUltrabug <ultrabug@gentoo.org>2015-02-10 22:03:41 +0100
committerUltrabug <ultrabug@gentoo.org>2015-02-10 22:03:41 +0100
commit6f04e87bc1ce5bd071b015e15d52c81778758195 (patch)
tree5bee2ddd35ca9324af0433320e5639fd619044c9
parente182f7a7a731ecf717c9d6c09351fbb85cc86cda (diff)
fix issue #63 wrt SIGUSR1 spam error, cap it to 1 per 100ms anyway to avoid killing i3status
-rwxr-xr-xpy3status/__init__.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/py3status/__init__.py b/py3status/__init__.py
index 9e21429..b2cf758 100755
--- a/py3status/__init__.py
+++ b/py3status/__init__.py
@@ -1080,8 +1080,9 @@ class Py3statusWrapper():
"""
Useful variables we'll need.
"""
- self.modules = {}
+ self.last_refresh_ts = time()
self.lock = Event()
+ self.modules = {}
self.py3_modules = []
def get_config(self):
@@ -1363,9 +1364,28 @@ class Py3statusWrapper():
def sig_handler(self, signum, frame):
"""
- Raise a Warning level exception when a user sends a SIGUSR1 signal.
+ SIGUSR1 was received, the user asks for an immediate refresh of the bar
+ so we force i3status to refresh by sending it a SIGUSR1
+ and we clear all py3status modules' cache.
+
+ To prevent abuse, we rate limit this function to 100ms.
"""
- raise UserWarning("received USR1, forcing refresh")
+ if time() > (self.last_refresh_ts + 0.1):
+ syslog(LOG_INFO, 'received USR1, forcing refresh')
+
+ # send SIGUSR1 to i3status
+ call(['killall', '-s', 'USR1', 'i3status'])
+
+ # clear the cache of all modules
+ self.clear_modules_cache()
+
+ # reset the refresh timestamp
+ self.last_refresh_ts = time()
+ else:
+ syslog(
+ LOG_INFO,
+ 'received USR1 but rate limit is in effect, calm down'
+ )
def clear_modules_cache(self):
"""