Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ def __init__(

self._wait = asyncio.create_task(self._handle_events())

def __aiter__(self):
"""
Iterate over the command output asynchronously.

:return: Async generator of command outputs
"""
return self._iterate_events().__aiter__()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.


async def _iterate_events(
self,
) -> AsyncGenerator[
Expand Down