feat: add async wrapper as extension module#4
Open
jgwesterlund wants to merge 10 commits intomainfrom
Open
Conversation
Merge pull request #1 from jgwesterlund/fix/ring-open-recovery-safety
lets hope, cause im tired....
Add AsyncSDSavior in sdsavior.aio with dedicated single-thread executor for thread safety. Implements async iteration that yields records in chunks to avoid list materialization. Import explicitly from sdsavior.aio. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
What does this change do?
Adds
AsyncSDSaviorinsdsavior.aioas a separate extension module wrappingSDSaviorfor asyncio applications. Uses a dedicated single-thread executor and asyncio.Lock for thread safety. Implements chunked async iteration to avoid list materialization.Why is this needed?
Enables using SDSavior in async applications without blocking the event loop. Per reviewer feedback, this is a separate extension module (not integrated into core
__init__.py) — users import explicitly fromsdsavior.aio.Key design decisions addressing reviewer bugs:
ThreadPoolExecutor(max_workers=1)by default (notrun_in_executorwith the default pool which runs parallel threads)iter_recordsis anAsyncIteratorthat yields records in chunks of 256, avoiding memory spikes for large ringsType of change
How was this tested?
8 new tests in
tests/test_async.py:from_seqfilteringAll 44 tests pass, 98% coverage, ruff clean, mypy clean.
Checklist
Notes for reviewers
AsyncSDSavioris NOT added to__init__.py.__all__— it's opt-in viafrom sdsavior.aio import AsyncSDSavior.Added
pytest-asyncioas a dev dependency andasyncio_mode = "auto"to pyproject.toml.Docs updated:
usage.md,api.md.