From ee7d045413a59ac6c9be922fee1c979d345e087d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Fri, 9 May 2025 17:15:38 +0200 Subject: [PATCH] :recycle: refactor function name and remove speedcopy fallback --- client/ayon_core/lib/file_transaction.py | 17 ++++++----------- .../plugins/publish/integrate_hero_version.py | 12 ++++-------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/client/ayon_core/lib/file_transaction.py b/client/ayon_core/lib/file_transaction.py index bf206b535c..d720ff8d30 100644 --- a/client/ayon_core/lib/file_transaction.py +++ b/client/ayon_core/lib/file_transaction.py @@ -1,18 +1,13 @@ import concurrent.futures import os import logging -import sys import errno from concurrent.futures import ThreadPoolExecutor, Future from typing import List, Optional from ayon_core.lib import create_hard_link -# this is needed until speedcopy for linux is fixed -if sys.platform == "win32": - from speedcopy import copyfile -else: - from shutil import copyfile +from speedcopy import copyfile class DuplicateDestinationError(ValueError): @@ -118,7 +113,7 @@ class FileTransaction: executor.submit(self._backup_file, dst, src) for dst, (src, _) in self._transfers.items() ] - as_completed_stop_and_raise_on_error( + wait_for_future_errors( executor, backup_futures, logger=self.log) # Submit transfer tasks @@ -126,7 +121,7 @@ class FileTransaction: executor.submit(self._transfer_file, dst, src, opts) for dst, (src, opts) in self._transfers.items() ] - as_completed_stop_and_raise_on_error( + wait_for_future_errors( executor, transfer_futures, logger=self.log) def _backup_file(self, dst, src): @@ -228,7 +223,7 @@ class FileTransaction: return src == dst -def as_completed_stop_and_raise_on_error( +def wait_for_future_errors( executor: ThreadPoolExecutor, futures: List[Future], logger: Optional[logging.Logger] = None): @@ -237,7 +232,7 @@ def as_completed_stop_and_raise_on_error( The ThreadPoolExecutor only cancels pending futures on exception but will still complete those that are running - each which also themselves could - fail. We log all exceptions, but re-raise the last exception only. + fail. We log all exceptions but re-raise the last exception only. """ if logger is None: logger = logging.getLogger(__name__) @@ -246,7 +241,7 @@ def as_completed_stop_and_raise_on_error( exception = future.exception() if exception: # As soon as an error occurs, stop executing more futures. - # Running workers however, will still complete so we also want + # Running workers, however, will still be complete, so we also want # to log those errors if any occurred on them. executor.shutdown(wait=True, cancel_futures=True) break diff --git a/client/ayon_core/plugins/publish/integrate_hero_version.py b/client/ayon_core/plugins/publish/integrate_hero_version.py index 1315c114c3..43f93da293 100644 --- a/client/ayon_core/plugins/publish/integrate_hero_version.py +++ b/client/ayon_core/plugins/publish/integrate_hero_version.py @@ -3,13 +3,9 @@ import copy import errno import itertools import shutil -import sys from concurrent.futures import ThreadPoolExecutor -# this is needed until speedcopy for linux is fixed -if sys.platform == "win32": - from speedcopy import copyfile -else: - from shutil import copyfile + +from speedcopy import copyfile import clique import pyblish.api @@ -21,7 +17,7 @@ from ayon_api.operations import ( from ayon_api.utils import create_entity_id from ayon_core.lib import create_hard_link, source_hash -from ayon_core.lib.file_transaction import as_completed_stop_and_raise_on_error +from ayon_core.lib.file_transaction import wait_for_future_errors from ayon_core.pipeline.publish import ( get_publish_template_name, OptionalPyblishPluginMixin, @@ -431,7 +427,7 @@ class IntegrateHeroVersion( src_to_dst_file_paths, other_file_paths_mapping ) ] - as_completed_stop_and_raise_on_error(executor, futures) + wait_for_future_errors(executor, futures) # Update prepared representation etity data with files # and integrate it to server.