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.
This commit is contained in:
Will Miao
2025-03-23 09:22:57 +08:00
parent f69b3d96b6
commit 93329abe8b
2 changed files with 5 additions and 6 deletions

View File

@@ -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

View File

@@ -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