Skip to content

Commit f34f62c

Browse files
committed
modify get_default_client
1 parent a41add3 commit f34f62c

4 files changed

Lines changed: 19 additions & 10 deletions

File tree

cozeloop/_client.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,14 +406,21 @@ def set_default_client(client: Client):
406406

407407
def get_default_client() -> Client:
408408
global _default_client
409-
if _default_client is None:
409+
temp_client = None
410+
with _client_lock:
411+
temp_client = _default_client
412+
if temp_client is None:
410413
with _client_lock:
411-
if _default_client is None:
412-
try:
413-
_default_client = new_client()
414-
atexit.register(_graceful_shutdown)
415-
except Exception as e:
416-
new_exception = e
414+
temp_client = _default_client
415+
if temp_client is None:
416+
try:
417+
temp_client = new_client()
418+
with _client_lock:
419+
_default_client = temp_client
420+
atexit.register(_graceful_shutdown)
421+
except Exception as e:
422+
new_exception = e
423+
with _client_lock:
417424
_default_client = _NoopClient(new_exception)
418425
return _default_client
419426

cozeloop/decorator/decorator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
from typing import Optional, Callable, Any, overload, Dict, Generic, Iterator, TypeVar, List, cast, AsyncIterator
55
from functools import wraps
66

7-
from langchain_core.runnables import RunnableLambda, RunnableConfig
8-
97
from cozeloop import Client, Span, start_span
108
from cozeloop.decorator.utils import is_async_func, is_gen_func, is_async_gen_func, is_class_func
119

@@ -333,6 +331,7 @@ async def scorer_leader(state: MyState) -> dict | str:
333331
"""
334332

335333
def decorator(func: Callable):
334+
from langchain_core.runnables import RunnableLambda, RunnableConfig
336335

337336
@wraps(func)
338337
def sync_wrapper(*args: Any, **kwargs: Any):

cozeloop/internal/trace/span.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@ def set_deployment_env(self, deployment_env: str) -> None:
398398
self.set_tags({DEPLOYMENT_ENV: deployment_env})
399399

400400
def set_finish_time(self, finish_time: datetime) -> None:
401+
"""
402+
Set the finish time of the span. DO NOT use this method unless you know what you are doing.
403+
"""
401404
self.finish_time = finish_time
402405

403406

cozeloop/span.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def set_deployment_env(self, deployment_env: str) -> None:
195195
@abstractmethod
196196
def set_finish_time(self, finish_time: datetime) -> None:
197197
"""
198-
Set the finish time of the span.
198+
Set the finish time of the span. DO NOT use this method unless you know what you are doing.
199199
"""
200200

201201

0 commit comments

Comments
 (0)