diff --git a/__init__.py b/__init__.py index ac2f0d6..aafced0 100644 --- a/__init__.py +++ b/__init__.py @@ -1,5 +1,5 @@ from .cache_cleaner import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS -__version__ = "1.0.0" +__version__ = "1.0.1" __all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"] \ No newline at end of file diff --git a/cache_cleaner.py b/cache_cleaner.py index 3ea8d55..1ca4ca6 100644 --- a/cache_cleaner.py +++ b/cache_cleaner.py @@ -1,5 +1,4 @@ -import aiohttp -import asyncio +import requests from server import PromptServer from comfy.comfy_types.node_typing import IO import json @@ -25,32 +24,31 @@ class CacheCleaner: DESCRIPTION = """Calls the ComfyUI API to free model and node cache. Returns the inputs unchanged and provides API call status.""" - async def _call_api(self,address): + def _call_api(self, address): headers = {'Content-Type': 'application/json'} payload = { "unload_models": True, "free_memory": True } - async with aiohttp.ClientSession() as session: - async with session.post(f"http://{address.replace('0.0.0.0','127.0.0.1')}/api/free", - headers=headers, - json=payload) as response: - return response.status + try: + response = requests.post( + f"http://{address.replace('0.0.0.0','127.0.0.1')}/api/free", + headers=headers, + json=payload, + timeout=10 + ) + return response.status_code + except requests.exceptions.RequestException as e: + raise Exception(f"Request failed: {str(e)}") - def clean_cache(self, clean_cache,anything=None, image_pass=None, model_pass=None): + def clean_cache(self, clean_cache, anything=None, image_pass=None, model_pass=None): status = "Cache cleaning skipped" + address = f"{PromptServer.instance.address}:{PromptServer.instance.port}" if clean_cache: try: - # Create event loop for async call if one doesn't exist - try: - loop = asyncio.get_event_loop() - except RuntimeError: - loop = asyncio.new_event_loop() - asyncio.set_event_loop(loop) - address=f"{PromptServer.instance.address}:{PromptServer.instance.port}" - status_code = loop.run_until_complete(self._call_api(address)) + status_code = self._call_api(address) if status_code == 200: status = "Cache cleaned successfully" @@ -59,10 +57,11 @@ Returns the inputs unchanged and provides API call status.""" except Exception as e: status = f"Error: Failed to call API - {str(e)}" print(f"CacheCleaner Error: {str(e)}") - status = f"Status:{status}\nServer address:{address}" + + status = f"Status: {status}\nServer address: {address}" print(f"CacheCleaner: {status}") - return (anything,image_pass, model_pass, status) + return (anything, image_pass, model_pass, status) NODE_CLASS_MAPPINGS = { "CacheCleaner": CacheCleaner diff --git a/pyproject.toml b/pyproject.toml index ae57b20..fa9cc0a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "cache-cleaner" description = "A custom node for ComfyUI that provides the ability to clear the cache directly from your workflow." -version = "1.0.0" +version = "1.0.1" license = {file = "LICENSE"} [project.urls]