Skip to content

Commit

Permalink
poller: save state before waiting for workers
Browse files Browse the repository at this point in the history
If workers hang stopping them will fail and we'll never save
the processing state. Looks like this has be broken for a while.

Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
kuba-moo committed Oct 29, 2024
1 parent 88c3ba7 commit efaf9c9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pw_poller.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ def run(self, life) -> None:
except KeyboardInterrupt:
pass # finally will still run, but don't splat
finally:
# Dump state before trying to stop workers, in case they hang
self._state['last_poll'] = prev_big_scan.timestamp()
self._state['done_series'] = list(self.seen_series)
with open('poller.state', 'w') as f:
json.dump(self._state, f)

log_open_sec(f"Stopping threads")
for worker in self._workers:
worker.should_die = True
Expand All @@ -258,12 +264,6 @@ def run(self, life) -> None:
worker.join()
log_end_sec()

self._state['last_poll'] = prev_big_scan.timestamp()
self._state['done_series'] = list(self.seen_series)
# Dump state
with open('poller.state', 'w') as f:
json.dump(self._state, f)


if __name__ == "__main__":
os.umask(0o002)
Expand Down

0 comments on commit efaf9c9

Please sign in to comment.