fix(memory): add thread-safe singleton initialization

- Add threading.Lock with double-check locking to ScopeManager
- Add asyncio.Lock with double-check locking to MemoryReflection
- Make reset_memory_metrics async with proper locking
- Update test fixtures to handle async reset functions
This commit is contained in:
2026-01-05 17:39:39 +01:00
parent 032738c8dd
commit c8ba23928e
5 changed files with 36 additions and 17 deletions

View File

@@ -499,10 +499,11 @@ async def get_memory_metrics() -> MemoryMetrics:
return _metrics
def reset_memory_metrics() -> None:
async def reset_memory_metrics() -> None:
"""Reset the singleton instance (for testing)."""
global _metrics
_metrics = None
async with _lock:
_metrics = None
# Convenience functions