Skip to content

@metric_scope always throws for async generators #128

@jaheyy

Description

@jaheyy

The async generator handling code in metric_scope has the following lines

except Exception as ex:
    await logger.flush()
    if not isinstance(ex, StopIteration):
        raise

But async generator never throws StopIteration. It throws AsyncStopIteration. Therefore, the exception is always raised when generator completes.

Furthermore, instead of using while True and relying on Exception handling for every iteration, we can just use async for ...: yield result syntax. Same goes for regular generator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions