Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
fix(python-sdk): use per-event-loop transport for async client (#1178)
joe-lombrozo-s-bot[bot]16c86d17d080
diff --git a/.changeset/new-moons-jog.md b/.changeset/new-moons-jog.mdnew file mode 100644index 000000000..99d6d20e6--- /dev/null+++ b/.changeset/new-moons-jog.md@@ -0,0 +1,5 @@+---+'@e2b/python-sdk': patch+---++Support multiple asyncio loopsdiff --git a/DEV.md b/DEV.mdindex 6a653cc8a..ef83fd7b2 100644--- a/DEV.md+++ b/DEV.md@@ -1,3 +1,3 @@# Releasing e2b cli-to create a changeset run `npx changeset`+to create a changeset run `pnpm run changeset`diff --git a/package.json b/package.jsonindex c68c76393..a6d450b6e 100644--- a/package.json+++ b/package.json@@ -14,7 +14,7 @@"lint": "pnpm --if-present --recursive run lint","typecheck": "pnpm --if-present --recursive run typecheck","format": "pnpm --if-present --recursive run format",- "changeset": "pnpx @changesets/cli"+ "changeset": "pnpm dlx @changesets/cli"},"packageManager": "[email protected]","dependencies": {diff --git a/packages/python-sdk/e2b/api/client_async/__init__.py b/packages/python-sdk/e2b/api/client_async/__init__.pyindex 7c592ac68..1e97a688b 100644--- a/packages/python-sdk/e2b/api/client_async/__init__.py+++ b/packages/python-sdk/e2b/api/client_async/__init__.py@@ -1,7 +1,8 @@+import asyncioimport httpximport logging-from typing import Optional+from typing import Dictfrom e2b.connection_config import ConnectionConfigfrom e2b.api import limits, AsyncApiClient@@ -19,7 +20,7 @@ def get_api_client(config: ConnectionConfig, **kwargs) -> AsyncApiClient:class AsyncTransportWithLogger(httpx.AsyncHTTPTransport):- singleton: Optional["AsyncTransportWithLogger"] = None+ _instances: Dict[int, "AsyncTransportWithLogger"] = {}async def handle_async_request(self, request):url = f"{request.url.scheme}://{request.url.host}{request.url.path}"@@ -37,12 +38,14 @@ class AsyncTransportWithLogger(httpx.AsyncHTTPTransport):def get_transport(config: ConnectionConfig) -> AsyncTransportWithLogger:- if AsyncTransportWithLogger.singleton is not None:- return AsyncTransportWithLogger.singleton+ loop_id = id(asyncio.get_running_loop())++ if loop_id in AsyncTransportWithLogger._instances:+ return AsyncTransportWithLogger._instances[loop_id]transport = AsyncTransportWithLogger(limits=limits,proxy=config.proxy,)- AsyncTransportWithLogger.singleton = transport+ AsyncTransportWithLogger._instances[loop_id] = transportreturn transport