diff --git a/data/example_config.yml b/data/example_config.yml index 2490068..6f9a7a8 100644 --- a/data/example_config.yml +++ b/data/example_config.yml @@ -61,6 +61,10 @@ bar: refresh: 1000 # Prefix to be printed before the text of the command. prefix: "DATE: " + # Linux real-time signal that, when received, will refresh the module + # instantly. For example, if you set this to `1`, run + # `pkill -RTMIN+1 easyconf-lemonbar`. + signal: 0 # Formatting options. These will only affect the text and padding of this # module. format: diff --git a/easyconf-lemonbar/Module.py b/easyconf-lemonbar/Module.py index 3646a7c..83da8e2 100644 --- a/easyconf-lemonbar/Module.py +++ b/easyconf-lemonbar/Module.py @@ -1,7 +1,7 @@ from threading import Thread from subprocess import run from time import sleep -from signal import SIGRTMIN, sigtimedwait +from signal import SIGRTMIN, SIGUSR1, sigtimedwait class Module: # All text that the module contains. Will be re-generated every time the @@ -105,9 +105,18 @@ class Module: break sleep(self.refresh) else: - sigtimedwait([self.signal], self.refresh) - + sig = sigtimedwait([self.signal], self.refresh) + if sig: + print("Recieved signal " + str(sig)) + continue def start_thread(self): thread = Thread(target=self.thread_callback) thread.start() + self.__ident = thread.ident + + def get_ident(self): + if self.__ident: + return self.__ident + else: + return None diff --git a/easyconf-lemonbar/SignalRouter.py b/easyconf-lemonbar/SignalRouter.py new file mode 100644 index 0000000..d9a975e --- /dev/null +++ b/easyconf-lemonbar/SignalRouter.py @@ -0,0 +1,13 @@ +from signal import SIGRTMIN, SIGTERM, pthread_kill, signal +from sys import exit +from threading import enumerate as th_enumerate + +class SignalRouter: + def term(self, sig, frame): + print("Term signal received! Safely closing threads!") + for thread in th_enumerate(): + pthread_kill(thread.ident, SIGTERM) + + def __init__(self): + signal(SIGTERM, self.term) + signal(SIGRTMIN, self.rtmin) diff --git a/easyconf-lemonbar/main.py b/easyconf-lemonbar/main.py index d4fe3ae..01f944c 100644 --- a/easyconf-lemonbar/main.py +++ b/easyconf-lemonbar/main.py @@ -1,3 +1,6 @@ +from os import getpid + +from SignalRouter import SignalRouter from Bar import Bar from Module import Module from parse_config_file import get_bar_config_and_module_config_list @@ -8,6 +11,10 @@ def main(): seperator = bar_config["seperator"] margin = bar_config["margin"] + print(getpid()) + + signal_router = SignalRouter() + bar = Bar(seperator, margin) for module_config in module_config_list: