Skip to content

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

Open
veeceey wants to merge 1 commit into
sanic-org:mainfrom
veeceey:fix/issue-3129
Open

Suppress Python 3.14 deprecation warnings for asyncio event loop policy APIs#3137
veeceey wants to merge 1 commit into
sanic-org:mainfrom
veeceey:fix/issue-3129

Conversation

@veeceey

@veeceey veeceey commented Feb 8, 2026

Copy link
Copy Markdown

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

@veeceey veeceey requested a review from a team as a code owner February 8, 2026 23:02
@codecov

codecov Bot commented Feb 8, 2026

Copy link
Copy Markdown

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 (94991da).

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.

@veeceey veeceey requested a review from a team as a code owner February 15, 2026 07:07
…cy APIs (sanic-org#3129)

Python 3.14 deprecates get_event_loop_policy() and set_event_loop_policy().
Wrap these calls to suppress DeprecationWarning on 3.14+ while maintaining
backward compatibility. Also replace get_event_loop_policy().get_event_loop()
with get_event_loop() in app.py.

Additional changes:
- Regenerate bandit baseline for bandit 1.9.x compatibility
- Set fail-fast: false in CI to prevent cascading failures from runner crashes
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