From 53dedd48ea8c5a4e4790e48b5bc8b7278575dc94 Mon Sep 17 00:00:00 2001 From: xuyan wang <35394786+wayyoungboy@users.noreply.github.com> Date: Wed, 13 Nov 2024 22:40:00 +0800 Subject: [PATCH] zip use process (#548) --- common/tool.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/common/tool.py b/common/tool.py index 758d584e..8bc526e8 100644 --- a/common/tool.py +++ b/common/tool.py @@ -16,6 +16,7 @@ """ from __future__ import absolute_import, division, print_function +import multiprocessing as mp import os import io @@ -679,16 +680,22 @@ def tar_gz_to_zip(temp_dir, tar_gz_file, output_zip, password, stdio): base_path = os.path.basename(root) files_to_compress.append(file_path) base_paths.append(base_path) - + stdio.verbose("start pyminizip compress_multiple") # 3. Compress the extracted files into a (possibly) encrypted zip file + zip_process = None if password: # Use pyminizip to create the encrypted zip file - pyminizip.compress_multiple(files_to_compress, base_paths, output_zip, password, 5) # 5 is the compression level + zip_process = mp.Process(target=pyminizip.compress_multiple, args=(files_to_compress, base_paths, output_zip, password, 5)) + # pyminizip.compress_multiple(files_to_compress, base_paths, output_zip, password, 5) # 5 is the compression level stdio.verbose("extracted files compressed into encrypted {0}".format(output_zip)) else: # Create an unencrypted zip file - pyminizip.compress_multiple(files_to_compress, base_paths, output_zip, None, 5) + zip_process = mp.Process(target=pyminizip.compress_multiple, args=(files_to_compress, base_paths, output_zip, None, 5)) + # pyminizip.compress_multiple(files_to_compress, base_paths, output_zip, None, 5) stdio.verbose("extracted files compressed into unencrypted {0}".format(output_zip)) + zip_process.start() + if zip_process is not None: + zip_process.join() # 4. Remove the extracted directory shutil.rmtree(extract_dir)