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
This commit is contained in:
Pavel Raiskup 2022-07-02 10:54:40 +02:00
commit bbc325efdb
2 changed files with 5 additions and 2 deletions

View file

@ -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):

View file

@ -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 <praiskup@redhat.com> - 1.6-4
- fix for very frequent next() call, rhbz#2103093
* Mon Jun 13 2022 Python Maint <python-maint@redhat.com> - 1.6-3
- Rebuilt for Python 3.11