Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix add_limit wrapper for async generators #1310

Closed
wants to merge 9 commits into from

Conversation

sultaniman
Copy link
Contributor

This PR is an attempt to address #1213

@sultaniman sultaniman self-assigned this May 2, 2024
@sultaniman sultaniman added bug Something isn't working enhancement New feature or request labels May 2, 2024
Copy link

netlify bot commented May 2, 2024

Deploy Preview for dlt-hub-docs ready!

Name Link
🔨 Latest commit 8e7fcd1
🔍 Latest deploy log https://app.netlify.com/sites/dlt-hub-docs/deploys/663b2fe86339fc0008afc4c6
😎 Deploy Preview https://deploy-preview-1310--dlt-hub-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

if i is not None:
count += 1
# async gen yields awaitable so we must count one awaitable more
# so the previous one is evaluated and yielded.
# new awaitable will be cancelled
if count == max_items + int(is_async_gen):
return
yield i
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we need to yield only after if section

@sultaniman sultaniman changed the title Yield after checks in add_limit wrapper generator WIP:Yield after checks in add_limit wrapper generator May 2, 2024
@sultaniman sultaniman changed the title WIP:Yield after checks in add_limit wrapper generator WIP: Fix add_limit wrapper for async generators May 2, 2024
@sultaniman sultaniman requested a review from sh-rp May 2, 2024 14:26
@sultaniman sultaniman force-pushed the fix/issue-1213-add-limit-overrun branch 2 times, most recently from 769874a to 33b5af6 Compare May 7, 2024 07:37
@sultaniman sultaniman marked this pull request as ready for review May 7, 2024 08:12
@sultaniman sultaniman changed the title WIP: Fix add_limit wrapper for async generators Fix add_limit wrapper for async generators May 7, 2024
while True:
if should_stop:
break
yield loop.run_until_complete(gen.__anext__()) # type: ignore[arg-type]
Copy link
Contributor Author

@sultaniman sultaniman May 7, 2024

Choose a reason for hiding this comment

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

I used eventloop because with the old implementation it has been complaining about not awaited generator when resource combined with .add_limit

tests/extract/test_sources.py::test_add_limit_async
  /[...]/dlt/dlt/extract/pipe_iterator.py:275: RuntimeWarning: coroutine 'wrap_async_iterator.<locals>.run' was never awaited
    pipe_item = next(gen)
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

@sultaniman sultaniman force-pushed the fix/issue-1213-add-limit-overrun branch from 33b5af6 to 8e7fcd1 Compare May 8, 2024 07:55
@rudolfix rudolfix assigned sh-rp and unassigned sultaniman May 27, 2024
@sh-rp sh-rp closed this May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants