Skip to content

Commit

Permalink
优化逻辑,增加多线程
Browse files Browse the repository at this point in the history
  • Loading branch information
SK-la committed Nov 2, 2024
1 parent 224a3ef commit bcc4249
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
12 changes: 6 additions & 6 deletions bin/Dispatch_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ async def process_file(bmson_file, output_folder, settings, error_list, cache_fo
tasks["large"].append(copy_if_not_exists(file_path, song_folder / f"{info.vdo}", existing_file_names_song))

# 批量执行所有任务
await asyncio.gather(*tasks["small"])
await asyncio.gather(*tasks["large"])
await asyncio.gather(*[await task for task in tasks["small"]])
await asyncio.gather(*[await task for task in tasks["large"]])
# 保存哈希缓存
await save_hash_cache(cache_folder, hash_cache)
return info
Expand All @@ -83,10 +83,10 @@ async def process_file(bmson_file, output_folder, settings, error_list, cache_fo
error_list.append((bmson_file, str(e)))
return None

finally:
# 确保文件句柄关闭
if 'file' in locals():
await file.close()
# finally:
# # 确保文件句柄关闭
# if 'file' in locals():
# await file.close()

async def copy_if_not_exists(file_path, destination_path, existing_file_names):
if not await compare_file_names(existing_file_names, destination_path.name):
Expand Down
3 changes: 1 addition & 2 deletions bin/aio.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import aiofiles
import asyncio
import datetime
import pathlib
from concurrent.futures import ThreadPoolExecutor

import aiofiles

from bin.Dispatch_file import process_file
from bin.utils import setup_custom_logger

Expand Down

0 comments on commit bcc4249

Please sign in to comment.