started implementing SignalRouter
This commit is contained in:
parent
eff5058382
commit
ebe2e2137e
4 changed files with 36 additions and 3 deletions
|
@ -61,6 +61,10 @@ bar:
|
||||||
refresh: 1000
|
refresh: 1000
|
||||||
# Prefix to be printed before the text of the command.
|
# Prefix to be printed before the text of the command.
|
||||||
prefix: "DATE: "
|
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
|
# Formatting options. These will only affect the text and padding of this
|
||||||
# module.
|
# module.
|
||||||
format:
|
format:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from subprocess import run
|
from subprocess import run
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from signal import SIGRTMIN, sigtimedwait
|
from signal import SIGRTMIN, SIGUSR1, sigtimedwait
|
||||||
|
|
||||||
class Module:
|
class Module:
|
||||||
# All text that the module contains. Will be re-generated every time the
|
# All text that the module contains. Will be re-generated every time the
|
||||||
|
@ -105,9 +105,18 @@ class Module:
|
||||||
break
|
break
|
||||||
sleep(self.refresh)
|
sleep(self.refresh)
|
||||||
else:
|
else:
|
||||||
sigtimedwait([self.signal], self.refresh)
|
sig = sigtimedwait([self.signal], self.refresh)
|
||||||
|
if sig:
|
||||||
|
print("Recieved signal " + str(sig))
|
||||||
|
continue
|
||||||
|
|
||||||
def start_thread(self):
|
def start_thread(self):
|
||||||
thread = Thread(target=self.thread_callback)
|
thread = Thread(target=self.thread_callback)
|
||||||
thread.start()
|
thread.start()
|
||||||
|
self.__ident = thread.ident
|
||||||
|
|
||||||
|
def get_ident(self):
|
||||||
|
if self.__ident:
|
||||||
|
return self.__ident
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
13
easyconf-lemonbar/SignalRouter.py
Normal file
13
easyconf-lemonbar/SignalRouter.py
Normal file
|
@ -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)
|
|
@ -1,3 +1,6 @@
|
||||||
|
from os import getpid
|
||||||
|
|
||||||
|
from SignalRouter import SignalRouter
|
||||||
from Bar import Bar
|
from Bar import Bar
|
||||||
from Module import Module
|
from Module import Module
|
||||||
from parse_config_file import get_bar_config_and_module_config_list
|
from parse_config_file import get_bar_config_and_module_config_list
|
||||||
|
@ -8,6 +11,10 @@ def main():
|
||||||
seperator = bar_config["seperator"]
|
seperator = bar_config["seperator"]
|
||||||
margin = bar_config["margin"]
|
margin = bar_config["margin"]
|
||||||
|
|
||||||
|
print(getpid())
|
||||||
|
|
||||||
|
signal_router = SignalRouter()
|
||||||
|
|
||||||
bar = Bar(seperator, margin)
|
bar = Bar(seperator, margin)
|
||||||
|
|
||||||
for module_config in module_config_list:
|
for module_config in module_config_list:
|
||||||
|
|
Loading…
Reference in a new issue