-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-129204: Fix asyncio memory leak in cancelled tasks by clearing internal references #129214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Clear callback chains and exception references in Task._step() to prevent reference retention Filter cancelled Task objects from event loop's ready queue in BaseEventLoop._run_once() Add TestTaskMemoryLeak test case to verify proper garbage collection of cancelled tasks Include module-level docstring explaining test purpose and methodology Addresses memory management issues reported in Issue python#129204
Clear callback chains and exception references in Task._step() to prevent reference retention Filter cancelled Task objects from event loop's ready queue in BaseEventLoop._run_once() Add TestTaskMemoryLeak test case to verify proper garbage collection of cancelled tasks Include module-level docstring explaining test purpose and methodology Addresses memory management issues reported in Issue python#129204
The following commit authors need to sign the Contributor License Agreement: |
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Unless the underlying code is changed, it is generally not a good idea to change comments, insert/delete spaces, add chinese(?) characters. They make bisecting, and reverting a change (in case of a regression) difficult for the maintainer. |
…Fixed some bugs, but retained some comments that I consider necessary.
…Fixed some bugs, but retained some comments that I consider necessary.
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Done |
Not sure this is related to #129204 , maybe a typo? |
gh-129204: Fix asyncio memory leak in cancelled tasks by clearing internal references
Linked Issue
Resolves GitHub Issue #129204
Problem Summary
A memory leak occurs when creating and cancelling large numbers of
asyncio.Task
objects due to:_callbacks
list_ready
queue_context
referencesSolution
1. Task Object Cleanup (
Lib/asyncio/tasks.py
)2. Event Loop Optimization (
Lib/asyncio/base_events.py
)3. Validation Tests (
Lib/test/test_asyncio/test_tasks.py
)Compatibility
Verification
Unit Tests
./python -m test test_asyncio -m TestTaskMemoryLeak
Expected: Tests pass with 0 leaked Task objects
Manual Validation
Additional Notes
Documentation Updates
Alternative Approaches Considered
Related Work
Inspired by memory management improvements in uvloop#412
Checklist
make test
passes on all supported platformstest_asyncio
suite shows 100% pass rate