From e45935a24953837498db7a68c4851d81825e4e7b Mon Sep 17 00:00:00 2001 From: Ultrabug Date: Tue, 16 Apr 2013 10:01:37 +0200 Subject: 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 --- py3status/__init__.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'py3status') 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): -- cgit v1.3