gh-155502: Warn about keeping a reference to tasks from loop.create_task - #155599
Draft
Khan3K wants to merge 1 commit into
Draft
gh-155502: Warn about keeping a reference to tasks from loop.create_task#155599Khan3K wants to merge 1 commit into
Khan3K wants to merge 1 commit into
Conversation
…eate_task The low-level Event Loop documentation for create_task() did not repeat the warning from the high-level asyncio.create_task() docs that the event loop only keeps weak references to tasks, so a task that is not referenced elsewhere may be garbage collected before it completes. Mirror the note (including the fire-and-forget collection pattern) in the loop.create_task() documentation.
Khan3K
requested review from
1st1,
asvetlov,
kumaraditya303 and
willingc
as code owners
August 12, 2026 04:21
|
The following commit authors need to sign the Contributor License Agreement: |
Documentation build overview
|
Member
|
You must sign the CLA before we can review. |
StanFromIreland
marked this pull request as draft
August 12, 2026 09:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The high-level :func:
asyncio.create_taskdocumentation warns that the event loop only keeps weak references to tasks and that unreferenced tasks may be garbage collected before they finish, but the low-level :meth:asyncio.loop.create_taskdocumentation did not repeat this warning.This mirrors the warning (including the "fire-and-forget" collection pattern and the :class:
asyncio.TaskGroupalternative) in the :meth:asyncio.loop.create_taskdocumentation, usingloop.create_taskin the example.Linked PRs