-
-
Notifications
You must be signed in to change notification settings - Fork 131
Fix ReAwaitable to support concurrent await calls (#2108) #2150
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
base: master
Are you sure you want to change the base?
Conversation
d9321b9
to
7086610
Compare
Sorry. Working on some missing tests. |
This is good to go. |
3bb27ec
to
f65832f
Compare
I pray this passes. |
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.
I added one more improvement so that it supports multiple async frameworks including asyncio, trio, and anyio, with automatic framework detection and fallback support. |
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.