Skip to content

Commit

Permalink
Stylize the while loop in SegmentGatherer.run
Browse files Browse the repository at this point in the history
  • Loading branch information
lahtinep committed Nov 13, 2024
1 parent fd8dcdf commit 3409378
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pytroll_collectors/segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,7 @@ def run(self):
signal.signal(signal.SIGTERM, self._handle_sigterm)

Check warning on line 716 in pytroll_collectors/segments.py

View check run for this annotation

Codecov / codecov/patch

pytroll_collectors/segments.py#L716

Added line #L716 was not covered by tests

self._loop = True
while self._loop:
if self._sigterm_caught and not self.slots:
self.stop()

while self._keep_running():

Check warning on line 719 in pytroll_collectors/segments.py

View check run for this annotation

Codecov / codecov/patch

pytroll_collectors/segments.py#L719

Added line #L719 was not covered by tests
self.triage_slots()

# Check listener for new messages
Expand All @@ -728,8 +725,7 @@ def run(self):
except AttributeError:
msg = self._listener.queue.get(True, 1)
except KeyboardInterrupt:
self.stop()
continue
break

Check warning on line 728 in pytroll_collectors/segments.py

View check run for this annotation

Codecov / codecov/patch

pytroll_collectors/segments.py#L728

Added line #L728 was not covered by tests
except Empty:
continue

Expand All @@ -739,11 +735,17 @@ def run(self):
continue
logger.info("New message received: %s", str(msg))
self.process(msg)
self.stop()

Check warning on line 738 in pytroll_collectors/segments.py

View check run for this annotation

Codecov / codecov/patch

pytroll_collectors/segments.py#L738

Added line #L738 was not covered by tests

def _handle_sigterm(self, signum, frame):
logging.info("Caught SIGTERM, shutting down when all collections are finished.")
self._sigterm_caught = True

Check warning on line 742 in pytroll_collectors/segments.py

View check run for this annotation

Codecov / codecov/patch

pytroll_collectors/segments.py#L741-L742

Added lines #L741 - L742 were not covered by tests

def _keep_running(self):
if not self._loop or (self._sigterm_caught and not self.slots):
return False
return True

Check warning on line 747 in pytroll_collectors/segments.py

View check run for this annotation

Codecov / codecov/patch

pytroll_collectors/segments.py#L745-L747

Added lines #L745 - L747 were not covered by tests

def triage_slots(self):
"""Check if there are slots ready for publication."""
slots = self.slots.copy()
Expand Down

0 comments on commit 3409378

Please sign in to comment.