mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-10-04 22:17:10 +08:00
discard aiofiles
This commit is contained in:
parent
2deb55df06
commit
b35ad9aeff
@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio, aiofiles, threading
|
import asyncio, threading
|
||||||
|
from functools import partial, wraps
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import mimetypes
|
import mimetypes
|
||||||
@ -8,8 +9,6 @@ import logging
|
|||||||
from typing import Set, List, Dict, Tuple, Literal
|
from typing import Set, List, Dict, Tuple, Literal
|
||||||
from collections.abc import Collection
|
from collections.abc import Collection
|
||||||
|
|
||||||
import aiofiles.os
|
|
||||||
|
|
||||||
supported_pt_extensions: set[str] = {'.ckpt', '.pt', '.bin', '.pth', '.safetensors', '.pkl', '.sft'}
|
supported_pt_extensions: set[str] = {'.ckpt', '.pt', '.bin', '.pth', '.safetensors', '.pkl', '.sft'}
|
||||||
|
|
||||||
folder_names_and_paths: dict[str, tuple[list[str], set[str]]] = {}
|
folder_names_and_paths: dict[str, tuple[list[str], set[str]]] = {}
|
||||||
@ -199,19 +198,19 @@ def recursive_search(directory: str, excluded_dir_names: list[str] | None=None)
|
|||||||
logging.debug("recursive file list on directory {}".format(directory))
|
logging.debug("recursive file list on directory {}".format(directory))
|
||||||
|
|
||||||
async def proc_subdir(path: str):
|
async def proc_subdir(path: str):
|
||||||
dirs[path] = await aiofiles.os.path.getmtime(path)
|
dirs[path] = await AsyncFiles.getmtime(path)
|
||||||
|
|
||||||
def proc_thread():
|
def proc_thread():
|
||||||
asyncio.set_event_loop(asyncio.new_event_loop())
|
asyncio.set_event_loop(asyncio.new_event_loop())
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
async def handle(file):
|
async def handle(file):
|
||||||
if not await aiofiles.os.path.isdir(file):
|
if not await AsyncFiles.isdir(file):
|
||||||
relative_path = os.path.relpath(file, directory)
|
relative_path = await AsyncFiles.relpath(file, directory)
|
||||||
result.append(relative_path)
|
result.append(relative_path)
|
||||||
return
|
return
|
||||||
calls.append(proc_subdir(file))
|
calls.append(proc_subdir(file))
|
||||||
for subdir in await aiofiles.os.listdir(file):
|
for subdir in await AsyncFiles.listdir(file):
|
||||||
path = os.path.join(file, subdir)
|
path = os.path.join(file, subdir)
|
||||||
if subdir not in excluded_dir_names:
|
if subdir not in excluded_dir_names:
|
||||||
calls.append(handle(path))
|
calls.append(handle(path))
|
||||||
@ -283,11 +282,11 @@ def cached_filename_list_(folder_name: str) -> tuple[list[str], dict[str, float]
|
|||||||
folders = folder_names_and_paths[folder_name]
|
folders = folder_names_and_paths[folder_name]
|
||||||
|
|
||||||
async def check_folder_mtime(folder: str, time_modified: float):
|
async def check_folder_mtime(folder: str, time_modified: float):
|
||||||
if await aiofiles.os.path.getmtime(folder) != time_modified:
|
if await AsyncFiles.getmtime(folder) != time_modified:
|
||||||
must_invalidate[0] = True
|
must_invalidate[0] = True
|
||||||
|
|
||||||
async def check_new_dirs(x: str):
|
async def check_new_dirs(x: str):
|
||||||
if await aiofiles.os.path.isdir(x):
|
if await AsyncFiles.isdir(x):
|
||||||
if x not in out[1]:
|
if x not in out[1]:
|
||||||
must_invalidate[0] = True
|
must_invalidate[0] = True
|
||||||
|
|
||||||
@ -371,3 +370,35 @@ def get_save_image_path(filename_prefix: str, output_dir: str, image_width=0, im
|
|||||||
os.makedirs(full_output_folder, exist_ok=True)
|
os.makedirs(full_output_folder, exist_ok=True)
|
||||||
counter = 1
|
counter = 1
|
||||||
return full_output_folder, filename, counter, subfolder, filename_prefix
|
return full_output_folder, filename, counter, subfolder, filename_prefix
|
||||||
|
|
||||||
|
|
||||||
|
def aio_wrap(func):
|
||||||
|
@wraps(func)
|
||||||
|
async def run(*args, loop=None, executor=None, **kwargs):
|
||||||
|
if loop is None:
|
||||||
|
loop = asyncio.get_running_loop()
|
||||||
|
pfunc = partial(func, *args, **kwargs)
|
||||||
|
return await loop.run_in_executor(executor, pfunc)
|
||||||
|
return run
|
||||||
|
|
||||||
|
|
||||||
|
class AsyncFiles:
|
||||||
|
@staticmethod
|
||||||
|
@aio_wrap
|
||||||
|
def listdir(path: str) -> list[str]:
|
||||||
|
return os.listdir(path)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@aio_wrap
|
||||||
|
def isdir(path: str) -> bool:
|
||||||
|
return os.path.isdir(path)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@aio_wrap
|
||||||
|
def getmtime(path: str) -> float:
|
||||||
|
return os.path.getmtime(path)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@aio_wrap
|
||||||
|
def relpath(file: str, directory: str) -> str:
|
||||||
|
return os.path.relpath(file, directory)
|
||||||
|
|||||||
@ -7,7 +7,6 @@ transformers>=4.28.1
|
|||||||
tokenizers>=0.13.3
|
tokenizers>=0.13.3
|
||||||
sentencepiece
|
sentencepiece
|
||||||
safetensors>=0.4.2
|
safetensors>=0.4.2
|
||||||
aiofiles
|
|
||||||
aiohttp
|
aiohttp
|
||||||
pyyaml
|
pyyaml
|
||||||
Pillow
|
Pillow
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user