fix(python-sdk): use per-event-loop transport for async client#1178
Open
joe-lombrozo-s-bot[bot] wants to merge 3 commits intomainfrom
Open
fix(python-sdk): use per-event-loop transport for async client#1178joe-lombrozo-s-bot[bot] wants to merge 3 commits intomainfrom
joe-lombrozo-s-bot[bot] wants to merge 3 commits intomainfrom
Conversation
The async get_transport() used a single class-level singleton, which assumes all callers share the same asyncio event loop. This breaks when the SDK is used across multiple event loops (e.g. multiple asyncio.run() calls, or threads with their own loops), because httpx async transports are bound to the loop they were first used on. Replace the singleton with a dict keyed by id(asyncio.get_running_loop()) so each event loop gets its own transport instance while still sharing within the same loop for connection pooling benefits.
🦋 Changeset detectedLatest commit: 3ab5af6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Package ArtifactsBuilt from 978c45b. Download artifacts from this workflow run. JS SDK ( npm install ./e2b-2.14.2-fix-async-transport-per-event-loop.0.tgzCLI ( npm install ./e2b-cli-2.8.1-fix-async-transport-per-event-loop.0.tgzPython SDK ( pip install ./e2b-2.15.1+fix.async.transport.per.event.loop-py3-none-any.whl |
dobrac
approved these changes
Mar 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The async
get_transport()in the Python SDK uses a single class-level singleton (AsyncTransportWithLogger.singleton) to share one transport across all callers. This assumes all async callers use the sameasyncioevent loop.This is an invalid assumption. Transports can be requested from different event loops when:
asyncio.run()is called multiple times (each creates a new loop)Since
httpxasync transports are bound to the event loop they were first used on, reusing a transport from a different loop causes errors.Fix
Replace the single
singletonclass variable with a_instancesdict keyed byid(asyncio.get_running_loop()). Each event loop gets its own transport instance while still sharing within the same loop for connection pooling benefits.The sync version doesn't have this issue since there's no event loop binding involved.
Changes
packages/python-sdk/e2b/api/client_async/__init__.py: Replace singleton with per-loop dict lookup