Skip to content

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

Open
mishushakov wants to merge 1 commit intomainfrom
mishushakov/async-teardown-fix
Open

test(python-sdk): parallelize async sandbox teardown#1309
mishushakov wants to merge 1 commit intomainfrom
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
Copy link
Copy Markdown

changeset-bot Bot commented Apr 30, 2026

⚠️ No Changeset found

Latest commit: b433ef4

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
Copy link
Copy Markdown

cursor Bot commented Apr 30, 2026

PR Summary

Low Risk
Test-only change to async fixture teardown; main risk is masking cleanup errors or altering timing due to concurrent kill() calls.

Overview
Updates the async_sandbox_factory pytest fixture teardown to kill all created sandboxes concurrently via asyncio.gather(..., return_exceptions=True) so one failing kill() no longer blocks cleanup of the others.

Also moves the _test_failed check outside the per-sandbox loop so failure logging is gated once per test while still printing each sandbox ID.

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

@github-actions
Copy link
Copy Markdown
Contributor

Package Artifacts

Built from 43cb9b9. Download artifacts from this workflow run.

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

npm install ./e2b-2.19.5-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.20.3+mishushakov-async-teardown-fix):

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

Copy link
Copy Markdown

@claude claude Bot left a comment

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant