fix(concurrency): add Python 3.14+ event loop compatibility #175
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.
Purpose
Fix Python 3.14+ compatibility where
asyncio.get_event_loop()now raisesRuntimeErrorinstead of returning a loop when none exists in the current thread.Changes
TL;DR
Updated
LoopManagerto useasyncio.get_running_loop()first, with a graceful fallback to policy-based loop retrieval/creation for Python 3.14+ compatibility. Added comprehensive test coverage for the fallback mechanism.Add compatibility layer for Python 3.14+ where
asyncio.get_event_loop()raises
RuntimeErrorwhen no event loop exists in the current thread._get_or_create_current_loop()method toLoopManagerclass thatattempts to get loop via policy, falling back to creating new loop if
RuntimeErroris raisedget_loop()to prioritizeasyncio.get_running_loop()for'current' strategy, falling back to policy-based approach when no
running loop exists
_get_isolated_loop()to useget_event_loop_policy().new_event_loop()for consistency with policy-based approach
test_get_loop_current_strategyto mockget_running_loop()instead of deprecated
get_event_loop()test_get_loop_isolated_strategyto mock policy instead ofdirect
new_event_loop()calltest_get_loop_current_strategy_fallbackto verify fallback topolicy when no running loop exists
test_get_loop_current_strategy_fallback_create_newto verifynew loop creation when policy raises
RuntimeError(Python 3.14+)Fixes: RuntimeError: There is no current event loop in thread 'MainThread'