fix: suppress Python 3.14 deprecation warnings for asyncio policy API (#3129)#3146
Open
r266-tech wants to merge 1 commit into
Open
fix: suppress Python 3.14 deprecation warnings for asyncio policy API (#3129)#3146r266-tech wants to merge 1 commit into
r266-tech wants to merge 1 commit into
Conversation
… policy Python 3.14 deprecates asyncio.get_event_loop_policy() and asyncio.set_event_loop_policy() with DeprecationWarning. These are still the recommended way to configure uvloop and Windows event loop policies, so we suppress the warnings on Python >= 3.14 where they originate from the asyncio module. Fixes sanic-org#3129
e56022e to
759a319
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3146 +/- ##
=============================================
- Coverage 87.793% 87.768% -0.025%
=============================================
Files 105 105
Lines 8143 8151 +8
Branches 1290 1292 +2
=============================================
+ Hits 7149 7154 +5
- Misses 687 690 +3
Partials 307 307 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
themavik
reviewed
Mar 23, 2026
themavik
left a comment
There was a problem hiding this comment.
module=asyncio in warnings.filterwarnings hides every DeprecationWarning from asyncio inside try_use_uvloop and try_windows_loop, not only the policy call. nit: narrow with message= if tests still pass.
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.
Description
Fixes #3129
Python 3.14 deprecates
asyncio.get_event_loop_policy()andasyncio.set_event_loop_policy()withDeprecationWarning. These APIs are still the recommended way to configure uvloop and Windows event loop policies, so the fix wraps calls inwarnings.catch_warnings()on Python >= 3.14 to suppress warnings originating from the asyncio module.Changes
sanic/server/loop.py: Wrapped event loop policy checks inwarnings.catch_warnings()blocks for bothtry_use_uvloop()andtry_windows_loop()functionsTesting
On Python 3.14, running Sanic with uvloop should no longer emit:
The pattern is intentionally kept simple — once Python 3.16 provides a
loop_factoryAPI, thewarnings.catch_warningswrapper can be replaced with directset_event_loop_factory()calls.