From cfdf4f86d844ebb362f4f39e9c6571d561b72897 Mon Sep 17 00:00:00 2001 From: Manuel Guidon <33161876+mguidon@users.noreply.github.com> Date: Wed, 16 Jun 2021 11:27:15 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=20Arbitrarily=20cap=20una?= =?UTF-8?q?rchiving=20to=202=20workers=20(#2384)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Cap unarchiving ProcessTool by default to 2 workers --- .../service-library/src/servicelib/archiving_utils.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/service-library/src/servicelib/archiving_utils.py b/packages/service-library/src/servicelib/archiving_utils.py index 6979eec1790..a8c2329e54d 100644 --- a/packages/service-library/src/servicelib/archiving_utils.py +++ b/packages/service-library/src/servicelib/archiving_utils.py @@ -5,6 +5,8 @@ from pathlib import Path from typing import Iterator, List, Set +MAX_UNARCHIVING_WORKER_COUNT = 2 + log = logging.getLogger(__name__) @@ -67,7 +69,10 @@ def ensure_destination_subdirectories_exist( async def unarchive_dir( - archive_to_extract: Path, destination_folder: Path + archive_to_extract: Path, + destination_folder: Path, + *, + max_workers: int = MAX_UNARCHIVING_WORKER_COUNT, ) -> Set[Path]: """Extracts zipped file archive_to_extract to destination_folder, preserving all relative files and folders inside the archive @@ -76,7 +81,7 @@ async def unarchive_dir( all tree leafs, which might include files or empty folders """ with zipfile.ZipFile(archive_to_extract, mode="r") as zip_file_handler: - with ProcessPoolExecutor() as pool: + with ProcessPoolExecutor(max_workers=max_workers) as pool: loop = asyncio.get_event_loop() # running in process poll is not ideal for concurrency issues @@ -135,7 +140,7 @@ def _serial_add_to_archive( async def archive_dir( dir_to_compress: Path, destination: Path, compress: bool, store_relative_path: bool ) -> bool: - """ Returns True if successuly archived """ + """Returns True if successuly archived""" with ProcessPoolExecutor(max_workers=1) as pool: return await asyncio.get_event_loop().run_in_executor( pool,