summaryrefslogtreecommitdiffstats
path: root/py3status
diff options
context:
space:
mode:
authorUltrabug <ultrabug@gentoo.org>2013-04-16 10:01:37 +0200
committerUltrabug <ultrabug@gentoo.org>2013-04-16 10:01:37 +0200
commite45935a24953837498db7a68c4851d81825e4e7b (patch)
tree9e013898bef56db88cc43b7009f5ac1a0fb7528a /py3status
parentfe9202bceb995171c507250c32ad5ffd13b452f8 (diff)
Handle killing of user-written modules nicely by calling their kill method if implemented upon exit of py3status, ignore kill methods execution when running normally
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 7efc179..47b1c4a 100755
--- a/py3status/__init__.py
+++ b/py3status/__init__.py
@@ -292,12 +292,14 @@ class UserModules(Thread):
def execute_classes(self):
"""
- run on every user class included and execute every method on the json,
- then cache it for later usage
+ Run on every user class included and execute every method on the json,
+ then cache it for later usage.
+ We exclude the 'kill' methods on the classes which are meant to be used
+ for convenience only.
"""
for class_name in sorted( self.classes.keys() ):
my_class, my_methods = self.classes[class_name]
- for my_method in my_methods:
+ for my_method in [ m for m in my_methods if m not in ['kill'] ]:
try:
# handle a cache on user class methods results
try:
@@ -334,8 +336,13 @@ class UserModules(Thread):
def stop(self):
"""
- break this thread's loop
+ call any 'kill' method on Py3status modules and break this thread's loop
"""
+ for class_name in sorted( self.classes.keys() ):
+ my_class, my_methods = self.classes[class_name]
+ if 'kill' in my_methods:
+ kill_module = getattr(my_class, 'kill')
+ kill_module()
self.kill = True
def clear(self):