From 7be020a96dc6c06f89df42935fb4e2356414cd67 Mon Sep 17 00:00:00 2001 From: Theo Li Date: Fri, 24 Jan 2025 19:02:20 +0800 Subject: [PATCH] feat: update default worker for megfile sync (#489) Co-authored-by: liyang --- megfile/cli.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/megfile/cli.py b/megfile/cli.py index e2eb0120..0e4b7c6b 100644 --- a/megfile/cli.py +++ b/megfile/cli.py @@ -366,7 +366,7 @@ def rm(path: str, recursive: bool): @click.argument("dst_path") @click.option("-g", "--progress-bar", is_flag=True, help="Show progress bar.") @click.option( - "-w", "--worker", type=click.INT, default=8, help="Number of concurrent workers." + "-w", "--worker", type=click.INT, default=-1, help="Number of concurrent workers." ) @click.option( "-f", "--force", is_flag=True, help="Copy files forcible, ignore same files." @@ -388,7 +388,8 @@ def sync( if not smart_exists(dst_path): force = True - with ThreadPoolExecutor(max_workers=worker) as executor: + max_workers = worker if worker > 0 else (os.cpu_count() or 1) * 2 + with ThreadPoolExecutor(max_workers=max_workers) as executor: if has_magic(src_path): src_root_path = get_non_glob_dir(src_path) if not smart_exists(src_root_path):