Skip to content

Conversation

@jaheyy
Copy link

@jaheyy jaheyy commented Dec 3, 2025

Fixes #128

This PR fixes the async generator bug where generators would always throw exceptions on completion due to incorrectly catching StopIteration instead of StopAsyncIteration.

Changes

Commit 1: Bug Fix (fix:)

  • Replace manual anext() calls with async for loop syntax
  • Replace manual next() calls with for loop syntax
  • Change exception handling from catching StopIteration to using try-finally
  • Async generators now properly complete without raising exceptions
  • Ensure metrics are always flushed even when exceptions occur

Commit 2: Performance Optimization (perf:)

  • Remove flush calls after each yield in generators
  • Metrics are now flushed only when generator completes (in finally block)
  • Improves performance by reducing flush operations
  • Maintains correctness with guaranteed flush on completion or exception

Blazej Gorny added 2 commits December 3, 2025 14:56
- Replace manual __anext__() calls with async for loop syntax
- Replace manual next() calls with for loop syntax
- Change exception handling from catching StopIteration to using try-finally
- Async generators now properly complete without raising exceptions
- Ensure metrics are always flushed even when exceptions occur

Fixes awslabs#128
…h yield

- Remove flush calls after each yield in generators
- Metrics are now flushed only when generator completes (in finally block)
- Improves performance by reducing flush operations
- Maintains correctness with guaranteed flush on completion or exception
@jaheyy jaheyy changed the title Fix/async generator stopiteration 128 Fix async generator stop iteration Dec 3, 2025
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.

@metric_scope always throws for async generators

1 participant