From 3dd5065c89803a51f7da217f850b161242a47686 Mon Sep 17 00:00:00 2001 From: Facetoe Date: Sun, 24 Sep 2017 14:36:57 +0800 Subject: [PATCH] Add toggle to enable keep_alive feature. (#610) Not all users execute i3pystatus directly, and this can cause issues when i3bar sends the SIGUSR2 signal. This commit places the keep_alive feature behind a flag in the Status module to be selectivly enabled by those that want to use it. Solves #609. --- i3pystatus/core/__init__.py | 5 +++-- i3pystatus/core/io.py | 11 +++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/i3pystatus/core/__init__.py b/i3pystatus/core/__init__.py index 2bb4506..2aebac4 100644 --- a/i3pystatus/core/__init__.py +++ b/i3pystatus/core/__init__.py @@ -59,11 +59,12 @@ class Status: :param bool click_events: Enable click events, if `standalone` is True. :param str logfile: Path to log file that will be used by i3pystatus. :param tuple internet_check: Address of server that will be used to check for internet connection by :py:class:`.internet`. + :param keep_alive: If True, modules that define the keep_alive flag will not be put to sleep when the status bar is hidden. """ def __init__(self, standalone=True, click_events=True, interval=1, input_stream=None, logfile=None, internet_check=None, - logformat=DEFAULT_LOG_FORMAT): + keep_alive=False, logformat=DEFAULT_LOG_FORMAT): self.standalone = standalone self.click_events = standalone and click_events input_stream = input_stream or sys.stdin @@ -83,7 +84,7 @@ class Status: self.modules = util.ModuleList(self, ClassFinder(Module)) if self.standalone: - self.io = io.StandaloneIO(self.click_events, self.modules, interval) + self.io = io.StandaloneIO(self.click_events, self.modules, keep_alive, interval) if self.click_events: self.command_endpoint = CommandEndpoint( self.modules, diff --git a/i3pystatus/core/io.py b/i3pystatus/core/io.py index ca45bd7..7ca6019 100644 --- a/i3pystatus/core/io.py +++ b/i3pystatus/core/io.py @@ -59,12 +59,10 @@ class StandaloneIO(IOHandler): { "version": 1, "click_events": True, - "stop_signal": signal.SIGUSR2, - "cont_signal": signal.SIGUSR2 }, "[", "[]", ",[]", ] - def __init__(self, click_events, modules, interval=1): + def __init__(self, click_events, modules, keep_alive, interval=1): """ StandaloneIO instance must be created in main thread to be able to set the SIGUSR1 signal handler. @@ -75,6 +73,12 @@ class StandaloneIO(IOHandler): self.modules = modules self.proto[0]['click_events'] = click_events + + if keep_alive: + self.proto[0].update(dict(stop_signal=signal.SIGUSR2, + cont_signal=signal.SIGUSR2)) + signal.signal(signal.SIGUSR2, self.suspend_signal_handler) + self.proto[0] = json.dumps(self.proto[0]) self.refresh_cond = Condition() @@ -82,7 +86,6 @@ class StandaloneIO(IOHandler): self.stopped = False signal.signal(signal.SIGUSR1, self.refresh_signal_handler) - signal.signal(signal.SIGUSR2, self.suspend_signal_handler) def read(self): self.compute_treshold_interval()