From 93329abe8b0d21d0354040541d2e21ed8f44865f Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Sun, 23 Mar 2025 09:22:57 +0800 Subject: [PATCH] Refactor LoraFileHandler to use provided event loop and improve logging - Updated LoraFileHandler to utilize the passed event loop for time retrieval instead of the current thread's event loop. - Changed error logging for extension loading in mappers from error to warning level for better clarity. --- py/services/file_monitor.py | 9 ++++----- py/workflow/mappers.py | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/py/services/file_monitor.py b/py/services/file_monitor.py index 849ba2a0..12a76120 100644 --- a/py/services/file_monitor.py +++ b/py/services/file_monitor.py @@ -32,7 +32,8 @@ class LoraFileHandler(FileSystemEventHandler): # Also check with backslashes for Windows compatibility alt_path = real_path.replace('/', '\\') - current_time = asyncio.get_event_loop().time() + # 使用传入的事件循环而不是尝试获取当前线程的事件循环 + current_time = self.loop.time() # Check if path is in ignore list and not expired if normalized_path in self._ignore_paths and self._ignore_paths[normalized_path] > current_time: @@ -59,8 +60,7 @@ class LoraFileHandler(FileSystemEventHandler): else: timeout = self._min_ignore_timeout - # Store expiration time instead of just the path - current_time = asyncio.get_event_loop().time() + current_time = self.loop.time() expiration_time = current_time + timeout # Store both normalized and alternative path formats @@ -72,8 +72,7 @@ class LoraFileHandler(FileSystemEventHandler): logger.debug(f"Added ignore path: {normalized_path} (expires in {timeout:.1f}s)") - # Schedule cleanup after timeout - asyncio.get_event_loop().call_later( + self.loop.call_later( timeout, self._remove_ignore_path, normalized_path diff --git a/py/workflow/mappers.py b/py/workflow/mappers.py index 0cdf0e0a..2f661521 100644 --- a/py/workflow/mappers.py +++ b/py/workflow/mappers.py @@ -421,7 +421,7 @@ def load_extensions(ext_dir: str = None) -> None: logger.info(f"Loaded extension mapper: {mapper.node_type} from {filename}") except Exception as e: - logger.error(f"Error loading extension {filename}: {e}") + logger.warning(f"Error loading extension {filename}: {e}") # Initialize the registry with default mappers