调试定时装饰器,优化代码
This commit is contained in:
@@ -102,8 +102,11 @@ class TaskRegistry:
|
|||||||
"""扫描已加载的模块,查找所有已创建的类实例"""
|
"""扫描已加载的模块,查找所有已创建的类实例"""
|
||||||
LOG.info("扫描已加载的模块,查找类实例...")
|
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:
|
if module_name.startswith('_') or not hasattr(module, '__file__') or module.__file__ is None:
|
||||||
continue
|
continue
|
||||||
@@ -128,7 +131,7 @@ class TaskRegistry:
|
|||||||
self.register_instance(var)
|
self.register_instance(var)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# 忽略获取属性时的错误
|
# 忽略获取属性时的错误
|
||||||
pass
|
LOG.debug(f"获取模块 {module_name} 的属性 {var_name} 时出错: {e}")
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
"""初始化任务系统,扫描所有已创建的实例并注册任务"""
|
"""初始化任务系统,扫描所有已创建的实例并注册任务"""
|
||||||
|
|||||||
Reference in New Issue
Block a user