Skip to content

Commit 35d054d

Browse files
authored
Use asyncio lock instead of anyio lock (#2807)
1 parent 46823ab commit 35d054d

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

pydantic_ai_slim/pydantic_ai/agent/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import inspect
55
import json
66
import warnings
7+
from asyncio import Lock
78
from collections.abc import AsyncIterator, Awaitable, Callable, Iterator, Sequence
89
from contextlib import AbstractAsyncContextManager, AsyncExitStack, asynccontextmanager, contextmanager
910
from contextvars import ContextVar
1011
from typing import TYPE_CHECKING, Any, ClassVar, cast, overload
1112

12-
import anyio
1313
from opentelemetry.trace import NoOpTracer, use_span
1414
from pydantic.json_schema import GenerateJsonSchema
1515
from typing_extensions import Self, TypeVar, deprecated
@@ -157,7 +157,7 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
157157

158158
_event_stream_handler: EventStreamHandler[AgentDepsT] | None = dataclasses.field(repr=False)
159159

160-
_enter_lock: anyio.Lock = dataclasses.field(repr=False)
160+
_enter_lock: Lock = dataclasses.field(repr=False)
161161
_entered_count: int = dataclasses.field(repr=False)
162162
_exit_stack: AsyncExitStack | None = dataclasses.field(repr=False)
163163

@@ -374,7 +374,7 @@ def __init__(
374374
_utils.Option[Sequence[Tool[AgentDepsT] | ToolFuncEither[AgentDepsT, ...]]]
375375
] = ContextVar('_override_tools', default=None)
376376

377-
self._enter_lock = anyio.Lock()
377+
self._enter_lock = Lock()
378378
self._entered_count = 0
379379
self._exit_stack = None
380380

pydantic_ai_slim/pydantic_ai/providers/google_vertex.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations as _annotations
22

33
import functools
4+
from asyncio import Lock
45
from collections.abc import AsyncGenerator, Mapping
56
from pathlib import Path
67
from typing import Literal, overload
@@ -118,7 +119,7 @@ def __init__(
118119
class _VertexAIAuth(httpx.Auth):
119120
"""Auth class for Vertex AI API."""
120121

121-
_refresh_lock: anyio.Lock = anyio.Lock()
122+
_refresh_lock: Lock = Lock()
122123

123124
credentials: BaseCredentials | ServiceAccountCredentials | None
124125

pydantic_ai_slim/pydantic_ai/toolsets/combined.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from __future__ import annotations
22

33
import asyncio
4+
from asyncio import Lock
45
from collections.abc import Callable, Sequence
56
from contextlib import AsyncExitStack
67
from dataclasses import dataclass, field, replace
78
from typing import Any
89

9-
import anyio
1010
from typing_extensions import Self
1111

1212
from .._run_context import AgentDepsT, RunContext
@@ -31,7 +31,7 @@ class CombinedToolset(AbstractToolset[AgentDepsT]):
3131

3232
toolsets: Sequence[AbstractToolset[AgentDepsT]]
3333

34-
_enter_lock: anyio.Lock = field(compare=False, init=False, default_factory=anyio.Lock)
34+
_enter_lock: Lock = field(compare=False, init=False, default_factory=Lock)
3535
_entered_count: int = field(init=False, default=0)
3636
_exit_stack: AsyncExitStack | None = field(init=False, default=None)
3737

0 commit comments

Comments
 (0)