From 6185a428a8cbfb77024879a3b618c8874aebf41b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 12 Sep 2022 15:33:37 +0200 Subject: [PATCH] Add-on: much faster processing of BAT progress messages BAT-packing is a multi-threaded operation, so messages about its progress are queued up in a thread-safe manner. The modal operator was only handling 4 messages per second, causing major slowdowns when there are lots of small files to be processed. This is now done much faster, and thus the UI shouldn't lag behind of the actual submissions progress. --- CHANGELOG.md | 5 +++++ addon/flamenco/operators.py | 23 ++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 012cc56b..26e721be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ This file contains the history of changes to Flamenco. Only changes that might be interesting for users are listed here, such as new features and fixes for bugs in actually-released versions. +## 3.0 - in development + +- Faster & more accurate progress reporting of file submission. + + ## 3.0-beta3 - released 2022-08-31 - Clean up how version numbers are reported, so that there are no repeats of the diff --git a/addon/flamenco/operators.py b/addon/flamenco/operators.py index 49f1861f..d67585d8 100644 --- a/addon/flamenco/operators.py +++ b/addon/flamenco/operators.py @@ -3,6 +3,7 @@ import datetime import logging +import time from pathlib import Path, PurePosixPath from typing import Optional, TYPE_CHECKING from urllib3.exceptions import HTTPError, MaxRetryError @@ -137,6 +138,7 @@ class FLAMENCO_OT_submit_job(FlamencoOpMixin, bpy.types.Operator): default=False, ) + TIMER_PERIOD = 0.25 # seconds timer: Optional[bpy.types.Timer] = None packthread: Optional[_PackThread] = None @@ -178,11 +180,22 @@ class FLAMENCO_OT_submit_job(FlamencoOpMixin, bpy.types.Operator): # If there is no pack thread running, there isn't much we can do. return self._quit(context) - msg = self.packthread.poll() - if not msg: - return {"RUNNING_MODAL"} + # Limit the time for which messages are processed. If there are no + # queued messages, this code stops immediately, but otherwise it will + # continue to process until the deadline. + deadline = time.monotonic() + 0.9 * self.TIMER_PERIOD + num_messages = 0 + msg = None + while time.monotonic() < deadline: + msg = self.packthread.poll() + if not msg: + break + num_messages += 1 + result = self._on_bat_pack_msg(context, msg) + if "RUNNING_MODAL" not in result: + return result - return self._on_bat_pack_msg(context, msg) + return {"RUNNING_MODAL"} def _check_manager(self, context: bpy.types.Context) -> str: """Check the Manager version & fetch the job storage directory. @@ -296,7 +309,7 @@ class FLAMENCO_OT_submit_job(FlamencoOpMixin, bpy.types.Operator): context.window_manager.modal_handler_add(self) wm = context.window_manager - self.timer = wm.event_timer_add(0.25, window=context.window) + self.timer = wm.event_timer_add(self.TIMER_PERIOD, window=context.window) return {"RUNNING_MODAL"}