From bbc325efdbd35e8dd63c597d0cca7ab9b3ab445b Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Sat, 2 Jul 2022 10:54:40 +0200 Subject: [PATCH] Make sure the SMA window has really at least 2 seconds This could cause problems on very unstable connections. When next() wasn't called for a long time, and then it was called very frequently (so time() returned 4x the same value) we were clean()ing the window.dequeue so much so we got "last" equal to "deque[0][0]", therefore counter/(last - deque[0][0]) could cause a division by zero. In theory, this would also solve some temporary situations when subsequent calls to time() did not return consecutive values: >>> a = time() ; b = time() ; a > b True Resolves: rhbz#2103093 Version: 1.6-4 --- 0001-fixup-moving-average-window.patch | 2 +- python-progress.spec | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/0001-fixup-moving-average-window.patch b/0001-fixup-moving-average-window.patch index 8b9de8e..844a6eb 100644 --- a/0001-fixup-moving-average-window.patch +++ b/0001-fixup-moving-average-window.patch @@ -77,7 +77,7 @@ index b434b30..71b2039 100644 + if self.max_items: + while len(self.deque) > self.max_items: + self.pop() -+ while len(self.deque) > 2 and self.last - self.deque[0][0] > float(self.max_seconds): ++ while len(self.deque) > 2 and self.last - self.deque[1][0] > float(self.max_seconds): + self.pop() + + def next(self, n, t): diff --git a/python-progress.spec b/python-progress.spec index 8fb8a2d..5b5e3ac 100644 --- a/python-progress.spec +++ b/python-progress.spec @@ -20,7 +20,7 @@ Name: python-%{pypi_name} Version: 1.6 -Release: 3%{?dist} +Release: 4%{?dist} Summary: Easy to use progress bars License: ISC @@ -98,6 +98,9 @@ rm -rf %{pypi_name}.egg-info %changelog +* Sat Jul 02 2022 Pavel Raiskup - 1.6-4 +- fix for very frequent next() call, rhbz#2103093 + * Mon Jun 13 2022 Python Maint - 1.6-3 - Rebuilt for Python 3.11