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.
This commit is contained in:
Facetoe 2017-09-24 14:36:57 +08:00 committed by GitHub
parent 27519031fe
commit 3dd5065c89
2 changed files with 10 additions and 6 deletions

View File

@ -59,11 +59,12 @@ class Status:
:param bool click_events: Enable click events, if `standalone` is True. :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 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 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, def __init__(self, standalone=True, click_events=True, interval=1,
input_stream=None, logfile=None, internet_check=None, input_stream=None, logfile=None, internet_check=None,
logformat=DEFAULT_LOG_FORMAT): keep_alive=False, logformat=DEFAULT_LOG_FORMAT):
self.standalone = standalone self.standalone = standalone
self.click_events = standalone and click_events self.click_events = standalone and click_events
input_stream = input_stream or sys.stdin input_stream = input_stream or sys.stdin
@ -83,7 +84,7 @@ class Status:
self.modules = util.ModuleList(self, ClassFinder(Module)) self.modules = util.ModuleList(self, ClassFinder(Module))
if self.standalone: 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: if self.click_events:
self.command_endpoint = CommandEndpoint( self.command_endpoint = CommandEndpoint(
self.modules, self.modules,

View File

@ -59,12 +59,10 @@ class StandaloneIO(IOHandler):
{ {
"version": 1, "version": 1,
"click_events": True, "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 StandaloneIO instance must be created in main thread to be able to set
the SIGUSR1 signal handler. the SIGUSR1 signal handler.
@ -75,6 +73,12 @@ class StandaloneIO(IOHandler):
self.modules = modules self.modules = modules
self.proto[0]['click_events'] = click_events 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.proto[0] = json.dumps(self.proto[0])
self.refresh_cond = Condition() self.refresh_cond = Condition()
@ -82,7 +86,6 @@ class StandaloneIO(IOHandler):
self.stopped = False self.stopped = False
signal.signal(signal.SIGUSR1, self.refresh_signal_handler) signal.signal(signal.SIGUSR1, self.refresh_signal_handler)
signal.signal(signal.SIGUSR2, self.suspend_signal_handler)
def read(self): def read(self):
self.compute_treshold_interval() self.compute_treshold_interval()