fix: make _get_loop_agent singleton thread-safe with double-checked locking
Some checks failed
Tests / lint (pull_request) Successful in 3s
Tests / test (pull_request) Failing after 1m25s

Fixes #446
This commit is contained in:
kimi
2026-03-19 14:14:26 -04:00
parent 98b1142820
commit f34fc9df15

View File

@@ -18,6 +18,7 @@ from __future__ import annotations
import asyncio
import logging
import re
import threading
import time
import uuid
from collections.abc import Callable
@@ -59,6 +60,7 @@ class AgenticResult:
# ---------------------------------------------------------------------------
_loop_agent = None
_loop_agent_lock = threading.Lock()
def _get_loop_agent():
@@ -69,9 +71,11 @@ def _get_loop_agent():
"""
global _loop_agent
if _loop_agent is None:
from timmy.agent import create_timmy
with _loop_agent_lock:
if _loop_agent is None:
from timmy.agent import create_timmy
_loop_agent = create_timmy()
_loop_agent = create_timmy()
return _loop_agent