From 340937898df3a221a0ac3fb901c9dafa603dff5e Mon Sep 17 00:00:00 2001 From: Panu Lahtinen Date: Wed, 13 Nov 2024 12:42:44 +0200 Subject: [PATCH] Stylize the while loop in SegmentGatherer.run --- pytroll_collectors/segments.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pytroll_collectors/segments.py b/pytroll_collectors/segments.py index 896a620..fabfab8 100644 --- a/pytroll_collectors/segments.py +++ b/pytroll_collectors/segments.py @@ -716,10 +716,7 @@ def run(self): signal.signal(signal.SIGTERM, self._handle_sigterm) self._loop = True - while self._loop: - if self._sigterm_caught and not self.slots: - self.stop() - + while self._keep_running(): self.triage_slots() # Check listener for new messages @@ -728,8 +725,7 @@ def run(self): except AttributeError: msg = self._listener.queue.get(True, 1) except KeyboardInterrupt: - self.stop() - continue + break except Empty: continue @@ -739,11 +735,17 @@ def run(self): continue logger.info("New message received: %s", str(msg)) self.process(msg) + self.stop() def _handle_sigterm(self, signum, frame): logging.info("Caught SIGTERM, shutting down when all collections are finished.") self._sigterm_caught = True + def _keep_running(self): + if not self._loop or (self._sigterm_caught and not self.slots): + return False + return True + def triage_slots(self): """Check if there are slots ready for publication.""" slots = self.slots.copy()