From 61c6288391299f68b6ae7522071c8bb8786d536b Mon Sep 17 00:00:00 2001 From: donoban Date: Mon, 22 Oct 2018 21:14:43 +0200 Subject: [PATCH 1/2] Avoid progress events flooding --- qubes/backup.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/qubes/backup.py b/qubes/backup.py index a3b4f7aa..4b01e06c 100644 --- a/qubes/backup.py +++ b/qubes/backup.py @@ -326,6 +326,8 @@ class Backup(object): #: callback for progress reporting. Will be called with one argument #: - progress in percents self.progress_callback = None + self.last_progress = 0 + self.last_progress_time = time.time() #: backup ID, needs to be unique (for a given user), #: not necessary unpredictable; automatically generated self.backup_id = datetime.datetime.now().strftime( @@ -512,11 +514,15 @@ class Backup(object): if not self.total_backup_bytes: return if callable(self.progress_callback): - progress = ( - 100 * (self._done_vms_bytes + self._current_vm_bytes) / - self.total_backup_bytes) - # pylint: disable=not-callable - self.progress_callback(progress) + if time.time() - self.last_progress_time >= 1: # avoid flooding + progress = ( + 100 * (self._done_vms_bytes + self._current_vm_bytes) / + self.total_backup_bytes) + if progress - self.last_progress >= 0.5: + self.last_progress = progress + self.last_progress_time = time.time() + # pylint: disable=not-callable + self.progress_callback(progress) def _add_vm_progress(self, bytes_done): self._current_vm_bytes += bytes_done From a2db90f85fc6ed725debae4491aff00133d3be85 Mon Sep 17 00:00:00 2001 From: donoban Date: Mon, 22 Oct 2018 22:12:46 +0200 Subject: [PATCH 2/2] progress thresold removed as Marek suggested --- qubes/backup.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/qubes/backup.py b/qubes/backup.py index 4b01e06c..8a644ec5 100644 --- a/qubes/backup.py +++ b/qubes/backup.py @@ -326,7 +326,6 @@ class Backup(object): #: callback for progress reporting. Will be called with one argument #: - progress in percents self.progress_callback = None - self.last_progress = 0 self.last_progress_time = time.time() #: backup ID, needs to be unique (for a given user), #: not necessary unpredictable; automatically generated @@ -518,11 +517,9 @@ class Backup(object): progress = ( 100 * (self._done_vms_bytes + self._current_vm_bytes) / self.total_backup_bytes) - if progress - self.last_progress >= 0.5: - self.last_progress = progress - self.last_progress_time = time.time() - # pylint: disable=not-callable - self.progress_callback(progress) + self.last_progress_time = time.time() + # pylint: disable=not-callable + self.progress_callback(progress) def _add_vm_progress(self, bytes_done): self._current_vm_bytes += bytes_done