Skip to content

fix: suppress Python 3.14 deprecation warnings for asyncio policy API (#3129)#3146

Open
r266-tech wants to merge 1 commit into
sanic-org:mainfrom
r266-tech:fix/py314-deprecation-warnings
Open

fix: suppress Python 3.14 deprecation warnings for asyncio policy API (#3129)#3146
r266-tech wants to merge 1 commit into
sanic-org:mainfrom
r266-tech:fix/py314-deprecation-warnings

Conversation

@r266-tech

@r266-tech r266-tech commented Mar 22, 2026

Copy link
Copy Markdown

Description

Fixes #3129

Python 3.14 deprecates asyncio.get_event_loop_policy() and asyncio.set_event_loop_policy() with DeprecationWarning. These APIs are still the recommended way to configure uvloop and Windows event loop policies, so the fix wraps calls in warnings.catch_warnings() on Python >= 3.14 to suppress warnings originating from the asyncio module.

Changes

  • sanic/server/loop.py: Wrapped event loop policy checks in warnings.catch_warnings() blocks for both try_use_uvloop() and try_windows_loop() functions

Testing

On Python 3.14, running Sanic with uvloop should no longer emit:

DeprecationWarning: 'asyncio.get_event_loop_policy' is deprecated and slated for removal in Python 3.16
DeprecationWarning: 'asyncio.set_event_loop_policy' is deprecated and slated for removal in Python 3.16

The pattern is intentionally kept simple — once Python 3.16 provides a loop_factory API, the warnings.catch_warnings wrapper can be replaced with direct set_event_loop_factory() calls.

@r266-tech r266-tech requested a review from a team as a code owner March 22, 2026 18:48
… 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
@r266-tech r266-tech force-pushed the fix/py314-deprecation-warnings branch from e56022e to 759a319 Compare March 22, 2026 19:18
@codecov

codecov Bot commented Mar 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 41.66667% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.768%. Comparing base (785d77f) to head (759a319).

Files with missing lines Patch % Lines
sanic/server/loop.py 41.666% 6 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@themavik themavik left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python 3.14 deprecation warnings for asyncio.get_event_loop_policy still present in 25.12.0

2 participants