diff --git a/job_decorators.py b/job_decorators.py index f4df065..9c61892 100644 --- a/job_decorators.py +++ b/job_decorators.py @@ -102,8 +102,11 @@ class TaskRegistry: """扫描已加载的模块,查找所有已创建的类实例""" LOG.info("扫描已加载的模块,查找类实例...") + # 创建sys.modules的副本,避免在迭代过程中字典大小变化导致的错误 + modules_copy = dict(sys.modules) + # 获取所有已加载的模块 - for module_name, module in sys.modules.items(): + for module_name, module in modules_copy.items(): # 跳过内置模块和标准库模块 if module_name.startswith('_') or not hasattr(module, '__file__') or module.__file__ is None: continue @@ -128,7 +131,7 @@ class TaskRegistry: self.register_instance(var) except Exception as e: # 忽略获取属性时的错误 - pass + LOG.debug(f"获取模块 {module_name} 的属性 {var_name} 时出错: {e}") def initialize(self): """初始化任务系统,扫描所有已创建的实例并注册任务"""