fix: suppress Python 3.14 deprecation warnings for asyncio policy API (#3129) - #3146
fix: suppress Python 3.14 deprecation warnings for asyncio policy API (#3129)#3146r266-tech wants to merge 2 commits into
Conversation
e56022e to
759a319
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3146 +/- ##
=============================================
- Coverage 87.769% 87.722% -0.048%
=============================================
Files 105 105
Lines 8152 8161 +9
Branches 1291 1293 +2
=============================================
+ Hits 7155 7159 +4
- Misses 692 696 +4
- Partials 305 306 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
… 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
Per review feedback, match only the event loop policy deprecation messages instead of suppressing every DeprecationWarning raised from the asyncio module.
759a319 to
4cdeaaf
Compare
|
Good catch, thanks. The filter is now narrowed to Verified on CPython 3.14.4: the policy warnings are suppressed — including Also rebased onto current |
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.