Skip to content

test(python-sdk): parallelize async sandbox teardown - #1309

Merged
mishushakov merged 2 commits into
mainfrom
mishushakov/async-teardown-fix
May 14, 2026
Merged

test(python-sdk): parallelize async sandbox teardown#1309
mishushakov merged 2 commits into
mainfrom
mishushakov/async-teardown-fix

Conversation

@mishushakov

Copy link
Copy Markdown
Member

Summary

  • Replace the sequential for sandbox in sandboxes: await sandbox.kill() teardown in async_sandbox_factory with asyncio.gather(..., return_exceptions=True) so a failure on one kill no longer blocks cleanup of the rest, and teardown runs concurrently.
  • Hoist the _test_failed check above the loop so the failure log is printed once per fixture rather than per sandbox.

Test plan

  • pnpm run format, pnpm run lint, pnpm run typecheck (python-sdk) all pass
  • pnpm run test against affected python async sandbox tests

🤖 Generated with Claude Code

Use asyncio.gather with return_exceptions so a failed kill() on one
sandbox doesn't block cleanup of the rest, and teardown runs concurrently.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Apr 30, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 69cc8b5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@cursor

cursor Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

PR Summary

Low Risk
Low risk test-fixture change, but teardown errors are now swallowed and only printed, which could hide cleanup issues in CI output.

Overview
Async sandbox teardown now uses asyncio.gather(..., return_exceptions=True) so one kill() failure won’t block cleanup of other sandboxes, and it logs any teardown exceptions separately; test-failure logging is gated once per fixture instead of inside the kill loop.

Reviewed by Cursor Bugbot for commit 69cc8b5. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Package Artifacts

Built from d68b2d7. Download artifacts from this workflow run.

JS SDK (e2b@2.20.1-mishushakov-async-teardown-fix.0):

npm install ./e2b-2.20.1-mishushakov-async-teardown-fix.0.tgz

CLI (@e2b/cli@2.10.2-mishushakov-async-teardown-fix.0):

npm install ./e2b-cli-2.10.2-mishushakov-async-teardown-fix.0.tgz

Python SDK (e2b==2.21.0+mishushakov-async-teardown-fix):

pip install ./e2b-2.21.0+mishushakov.async.teardown.fix-py3-none-any.whl

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — straightforward test fixture cleanup parallelization.

Extended reasoning...

Overview

This PR modifies a single test fixture file (packages/python-sdk/tests/conftest.py) in the async_sandbox_factory fixture. It replaces a sequential for sandbox in sandboxes: await sandbox.kill() teardown loop with asyncio.gather(..., return_exceptions=True) for concurrent cleanup, and hoists the _test_failed check above the loop so the failure log prints once per fixture rather than per sandbox.

Security risks

None. This is test-only code (tests/conftest.py), not shipped or used in production. There is no auth, crypto, or permissions logic involved.

Level of scrutiny

Low scrutiny is appropriate. The change is a small, mechanical optimization to test teardown logic. return_exceptions=True preserves the previous swallow-errors behavior of the original try/except, so semantics are preserved while gaining concurrency. The hoisted _test_failed check is a clear correctness improvement (avoids duplicated log lines).

Other factors

The change is self-contained, limited to ~10 lines, and follows an established pattern. The changeset-bot warning about no changeset is expected and acceptable for a test-only change. No bugs were flagged by the bug hunting system.

Comment thread packages/python-sdk/tests/conftest.py Outdated
Surface which sandbox failed to kill instead of swallowing silently,
without failing the test from teardown.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@cla-bot cla-bot Bot added the cla-signed label May 14, 2026
@mishushakov
mishushakov enabled auto-merge (squash) May 14, 2026 12:43
@mishushakov
mishushakov merged commit 575339b into main May 14, 2026
36 of 37 checks passed
@mishushakov
mishushakov deleted the mishushakov/async-teardown-fix branch May 14, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants