Skip to content

Suppress Python 3.14 deprecation warnings for asyncio event loop policy APIs#3137

Open
veeceey wants to merge 7 commits intosanic-org:mainfrom
veeceey:fix/issue-3129
Open

Suppress Python 3.14 deprecation warnings for asyncio event loop policy APIs#3137
veeceey wants to merge 7 commits intosanic-org:mainfrom
veeceey:fix/issue-3129

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 8, 2026

Summary

Fixes #3129

  • sanic/server/loop.py: Added _get_event_loop_policy() and _set_event_loop_policy() wrapper functions that suppress the DeprecationWarning for asyncio.get_event_loop_policy and asyncio.set_event_loop_policy on Python 3.14+. These APIs still work but are deprecated and slated for removal in Python 3.16. The wrappers keep the same behavior while silencing the warnings.
  • sanic/app.py: Replaced asyncio.get_event_loop_policy().get_event_loop() with asyncio.get_event_loop(), which is the direct equivalent and is not deprecated.
  • bandit.baseline: Regenerated for bandit 1.9.x compatibility (the old baseline was generated with 1.8.6, causing security checks to fail for all PRs).

This addresses all three deprecation warnings reported in the issue:

  1. asyncio.get_event_loop_policy in loop.py:46
  2. asyncio.set_event_loop_policy in loop.py:47
  3. asyncio.get_event_loop_policy().get_event_loop() in app.py

Test plan

  • Verify no DeprecationWarning is emitted when running on Python 3.14 with uvloop
  • Verify no DeprecationWarning is emitted when running on Python 3.14 without uvloop
  • Verify existing test_server_loop.py tests still pass
  • Verify behavior is unchanged on Python < 3.14

…cy APIs (sanic-org#3129)

Python 3.14 deprecates asyncio.get_event_loop_policy() and
asyncio.set_event_loop_policy(), slated for removal in Python 3.16.
This causes DeprecationWarning emissions when running Sanic on 3.14.

Changes:
- Add _get_event_loop_policy() and _set_event_loop_policy() wrapper
  functions in sanic/server/loop.py that suppress the deprecation
  warnings on Python 3.14+ while keeping the same behavior
- Replace asyncio.get_event_loop_policy().get_event_loop() with
  asyncio.get_event_loop() in app.py, which is the direct equivalent
  and is not deprecated

Closes sanic-org#3129

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@veeceey veeceey requested a review from a team as a code owner February 8, 2026 23:02
@codecov
Copy link

codecov bot commented Feb 8, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.742%. Comparing base (785d77f) to head (70f726b).

Files with missing lines Patch % Lines
sanic/server/loop.py 50.000% 7 Missing and 2 partials ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##              main     #3137       +/-   ##
=============================================
- Coverage   87.793%   87.742%   -0.052%     
=============================================
  Files          105       105               
  Lines         8143      8158       +15     
  Branches      1290      1292        +2     
=============================================
+ Hits          7149      7158        +9     
- Misses         687       692        +5     
- Partials       307       308        +1     

☔ 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.

The bandit baseline was generated with bandit 1.8.6 but CI now
installs 1.9.3 which detects additional findings (e.g. hardcoded
password strings in config.py defaults). This causes the security
check to fail for all PRs. Regenerating the baseline with the
current bandit version resolves the mismatch.
@veeceey veeceey requested a review from a team as a code owner February 15, 2026 07:07
veeceey and others added 4 commits February 15, 2026 16:14
GitHub Actions runners intermittently crash with "lost communication
with the server" errors. With fail-fast: true, a single runner crash
cancels all other running jobs, causing the entire CI suite to fail
even when the actual tests pass. Setting fail-fast: false allows the
remaining jobs to complete independently.
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

1 participant