ruff
This commit is contained in:
@@ -10,6 +10,7 @@ from typing import Any
|
||||
import numpy as np
|
||||
|
||||
from src.config.config import model_config
|
||||
|
||||
from . import BaseDataModel
|
||||
|
||||
|
||||
|
||||
@@ -9,11 +9,10 @@
|
||||
|
||||
import asyncio
|
||||
import time
|
||||
from collections import defaultdict
|
||||
from collections import OrderedDict, defaultdict
|
||||
from collections.abc import Awaitable, Callable
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
from collections import OrderedDict
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
@@ -122,7 +122,7 @@ class BroadcastLogHandler(logging.Handler):
|
||||
try:
|
||||
# 导入logger元数据获取函数
|
||||
from src.common.logger import get_logger_meta
|
||||
|
||||
|
||||
return get_logger_meta(logger_name)
|
||||
except Exception:
|
||||
# 如果获取失败,返回空元数据
|
||||
@@ -138,7 +138,7 @@ class BroadcastLogHandler(logging.Handler):
|
||||
try:
|
||||
# 获取logger元数据(别名和颜色)
|
||||
logger_meta = self._get_logger_metadata(record.name)
|
||||
|
||||
|
||||
# 转换日志记录为字典
|
||||
log_dict = {
|
||||
"timestamp": self.format_time(record),
|
||||
@@ -146,7 +146,7 @@ class BroadcastLogHandler(logging.Handler):
|
||||
"logger_name": record.name, # 原始logger名称
|
||||
"event": record.getMessage(),
|
||||
}
|
||||
|
||||
|
||||
# 添加别名和颜色(如果存在)
|
||||
if logger_meta["alias"]:
|
||||
log_dict["alias"] = logger_meta["alias"]
|
||||
|
||||
@@ -34,7 +34,7 @@ def get_accurate_size(obj: Any, seen: set | None = None, max_depth: int = 3, _cu
|
||||
# 深度限制:防止递归爆炸
|
||||
if _current_depth >= max_depth:
|
||||
return sys.getsizeof(obj)
|
||||
|
||||
|
||||
# 对象数量限制:防止内存爆炸
|
||||
if len(seen) > 10000:
|
||||
return sys.getsizeof(obj)
|
||||
@@ -55,7 +55,7 @@ def get_accurate_size(obj: Any, seen: set | None = None, max_depth: int = 3, _cu
|
||||
if isinstance(obj, dict):
|
||||
# 限制处理的键值对数量
|
||||
items = list(obj.items())[:1000] # 最多处理1000个键值对
|
||||
size += sum(get_accurate_size(k, seen, max_depth, _current_depth + 1) +
|
||||
size += sum(get_accurate_size(k, seen, max_depth, _current_depth + 1) +
|
||||
get_accurate_size(v, seen, max_depth, _current_depth + 1)
|
||||
for k, v in items)
|
||||
|
||||
@@ -204,7 +204,7 @@ def estimate_cache_item_size(obj: Any) -> int:
|
||||
if pickle_size > 0:
|
||||
# pickle 通常略小于实际内存,乘以1.5作为安全系数
|
||||
return int(pickle_size * 1.5)
|
||||
|
||||
|
||||
# 方法2: 智能估算(深度受限,采样大容器)
|
||||
try:
|
||||
smart_size = estimate_size_smart(obj, max_depth=5, sample_large=True)
|
||||
|
||||
Reference in New Issue
Block a user