fix: add __aiter__ to AsyncCommandHandle for async iteration support#1192
fix: add __aiter__ to AsyncCommandHandle for async iteration support#1192MaxwellCalkin wants to merge 1 commit intoe2b-dev:mainfrom
Conversation
The sync CommandHandle supports `for stdout, stderr, pty in handle:` via __iter__, but AsyncCommandHandle lacks __aiter__, preventing `async for stdout, stderr, pty in handle:` usage. This adds __aiter__ mirroring the sync __iter__ pattern, delegating to the existing _iterate_events() async generator. Related to e2b-dev#1034 AI Disclosure: This commit was authored by Claude Opus 4.6 (Anthropic), operated by Maxwell Calkin (@MaxwellCalkin).
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ad4e2b6c27
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| :return: Async generator of command outputs | ||
| """ | ||
| return self._iterate_events().__aiter__() |
There was a problem hiding this comment.
Avoid a second consumer in
__aiter__
AsyncCommandHandle already starts self._wait = asyncio.create_task(self._handle_events()) in __init__, so the event stream is being consumed immediately in the background; returning a fresh self._iterate_events() iterator here introduces a second concurrent consumer of the same async generator. In the intended usage (async for ... in handle), this can raise RuntimeError: anext(): asynchronous generator is already running (or silently drain events in one consumer), so the new async-iteration API is not reliably usable.
Useful? React with 👍 / 👎.
Summary
Related to #1034
The sync
CommandHandlesupports iteration via__iter__:But
AsyncCommandHandlelacks__aiter__, so the async equivalent fails:This PR adds
__aiter__toAsyncCommandHandle, delegating to the existing_iterate_events()async generator — mirroring the sync__iter__→_handle_events()pattern.Changes
packages/python-sdk/e2b/sandbox_async/commands/command_handle.py: Added__aiter__method (8 lines)AI Disclosure
This PR was authored by Claude Opus 4.6 (Anthropic), an AI agent operated by Maxwell Calkin (@MaxwellCalkin). See our portfolio for more about this project.