From a08ca5b1b54cb66d5e89ed11b5709fa92780a646 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sun, 21 Mar 2021 16:47:22 +0100 Subject: [PATCH] avoid division by zero in progress meter On Windows systems the timer may not be accurate enough to measure the time between init() and done(). Avoid computing statistics with a diff time of 0 in such cases. Fixes #2230. --- nominatim/indexer/progress.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/nominatim/indexer/progress.py b/nominatim/indexer/progress.py index c9d8816b..177e67b8 100644 --- a/nominatim/indexer/progress.py +++ b/nominatim/indexer/progress.py @@ -57,8 +57,14 @@ class ProgressLogger: """ Print final statistics about the progress. """ rank_end_time = datetime.now() - diff_seconds = (rank_end_time-self.rank_start_time).total_seconds() + + if rank_end_time == self.rank_start_time: + diff_seconds = 0 + places_per_sec = self.done_places + else: + diff_seconds = (rank_end_time - self.rank_start_time).total_seconds() + places_per_sec = self.done_places/diff_seconds LOG.warning("Done %d/%d in %d @ %.3f per second - FINISHED %s\n", self.done_places, self.total_places, int(diff_seconds), - self.done_places/diff_seconds, self.name) + places_per_sec, self.name) -- 2.45.1