python / python/cpython

asyncio Event Loop does not provide warning about keeping a reference to returned task

Open
#155,502 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

docs topic-asyncio
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Documentation

The high level asyncio documentation warns that one should save the result of asyncio.create_task as the event loop only keeps weak references to tasks.
This same warning is not seen in the low level Event Loop documentation even though the same rules apply. The example code snippets also do not save a reference which would lead readers to believe it is safe to discard the result of the EventLoop.create_task function when it is not.

Relevant function in the high level documentation: https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task

Relevant function in the low level documentation: https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.create_task

Linked PRs
  • gh-155599

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Compare the asyncio.create_task documentation with the asyncio.loop.create_task section at the two linked documentation URLs. Update the low-level warning and its examples so they reflect the reference-lifetime guidance from the high-level documentation, then verify both sections are consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.