Fix ReAwaitable to support concurrent await calls (#2108)#2150
Open
AdrianAcala wants to merge 1 commit intodry-python:masterfrom
Open
Fix ReAwaitable to support concurrent await calls (#2108)#2150AdrianAcala wants to merge 1 commit intodry-python:masterfrom
AdrianAcala wants to merge 1 commit intodry-python:masterfrom
Conversation
d9321b9 to
7086610
Compare
Author
|
Sorry. Working on some missing tests. |
Author
|
This is good to go. |
3bb27ec to
f65832f
Compare
Author
|
I pray this passes. |
Author
|
I used |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2150 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 80 81 +1
Lines 2485 2586 +101
Branches 437 45 -392
==========================================
+ Hits 2485 2586 +101 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
21a4b58 to
8cb3088
Compare
…rage This commit resolves the race condition in concurrent await scenarios and adds comprehensive multi-framework async support with enhanced test coverage. ## Key Changes: **ReAwaitable Enhancements:** - Resolve race condition in concurrent await scenarios by properly handling asyncio locks and coroutine state management - Add full support for trio and anyio async frameworks beyond asyncio - Implement intelligent framework detection with graceful fallbacks (asyncio → trio → anyio → threading) - Add comprehensive DEBUG-level logging for lock fallback scenarios to aid troubleshooting - Achieve thread-safe concurrent await support across all major Python async frameworks - Refactor implementation to reduce complexity and improve maintainability **Test Infrastructure:** - Achieve 100% branch coverage with comprehensive test cases - Add extensive tests for all framework scenarios and edge cases - Add comprehensive tests for logging functionality across all framework scenarios - Refactor tests into focused helper functions for better maintainability - Add safe private attribute access helpers to improve test reliability - Enable pytest-asyncio auto mode for better test infrastructure **CI/Build Improvements:** - Update CI workflow to use correct Poetry installation path (.local/bin) - Fix mypy plugin compatibility and test infrastructure for CI - Add pytest-asyncio dependency for async test support **Documentation:** - Update documentation to reflect enhanced framework compatibility - Add detailed docstring documenting framework precedence order - Add changelog entry for the bug fix This addresses issue dry-python#2108 where trio/anyio users experienced "coroutine is being awaited already" errors with concurrent awaits. The implementation now provides thread-safe concurrent await support across all major Python async frameworks.
Author
|
I added one more improvement so that it supports multiple async frameworks including asyncio, trio, and anyio, with automatic framework detection and fallback support. |
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.
Fix ReAwaitable to support concurrent await calls
This PR adds thread-safe caching with asyncio.Lock to prevent race conditions when multiple tasks await the same ReAwaitable instance concurrently. The implementation maintains backward compatibility for non-asyncio environments.
Changes made:
Why this change is needed:
Previously, when multiple async tasks awaited the same ReAwaitable instance simultaneously, race conditions could occur leading to the underlying coroutine being executed multiple times. This fix ensures that only one task executes the coroutine while others wait and receive the cached result.
Checklist
Related issues
🙏 Please, if you or your company finds dry-python valuable, help us sustain the project by sponsoring it transparently on https://github.com/sponsors/dry-python. As a thank you, your profile/company logo will be added to our main README which receives hundreds of unique visitors per day.