From 38198425685b44a70d585b7e209adcaa1aaa27fe Mon Sep 17 00:00:00 2001 From: Ultrabug Date: Sun, 2 Oct 2022 17:50:13 +0200 Subject: [PATCH] core: simpler logic to inhibit out of order signaling (#2147) --- py3status/core.py | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/py3status/core.py b/py3status/core.py index d2b5ed86e8..9cd24ae3f2 100644 --- a/py3status/core.py +++ b/py3status/core.py @@ -251,12 +251,10 @@ def __init__(self, options): """ self.config = vars(options) self.i3bar_running = True - self.last_loop_ts = time.monotonic() self.last_refresh_ts = time.monotonic() - self.last_sigcont_ts = None - self.last_sigtstp_ts = None self.lock = Event() self.modules = {} + self.next_allowed_signal = SIGTSTP self.notified_messages = set() self.options = options self.output_modules = {} @@ -1020,27 +1018,24 @@ def process_module_output(self, module): return ",".join(dumps(x) for x in outputs) def i3bar_stop(self, signum, frame): - if ( - self.last_sigcont_ts - and self.last_sigtstp_ts - and self.last_sigcont_ts > self.last_sigtstp_ts - and time.monotonic() - self.last_loop_ts < 1 - ): + if self.next_allowed_signal == signum: self.log(f"received stop_signal {Signals(signum).name}") self.i3bar_running = False # i3status should be stopped self.i3status_thread.suspend_i3status() self.sleep_modules() + self.next_allowed_signal = SIGCONT else: self.log(f"inhibited stop_signal {Signals(signum).name}", level="warning") - self.last_sigtstp_ts = time.monotonic() def i3bar_start(self, signum, frame): - self.log(f"received resume signal {Signals(signum).name}") - self.last_loop_ts = time.monotonic() - self.last_sigcont_ts = time.monotonic() - self.i3bar_running = True - self.wake_modules() + if self.next_allowed_signal == signum: + self.log(f"received resume signal {Signals(signum).name}") + self.i3bar_running = True + self.wake_modules() + self.next_allowed_signal = self.stop_signal + else: + self.log(f"inhibited start_signal {Signals(signum).name}", level="warning") def sleep_modules(self): # Put all py3modules to sleep so they stop updating @@ -1111,8 +1106,6 @@ def run(self): while not self.i3bar_running: time.sleep(0.1) - self.last_loop_ts = time.monotonic() - # check if an update is needed if self.update_queue: while len(self.update_queue):