FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-131837: Clarify context variable lifetime in closures by limadog9 · Pull Request #159849 · python/cpython · GitHub

Repository navigation

gh-131837: Clarify context variable lifetime in closures - #159849

Closed
limadog9 wants to merge 1 commit into
python:mainfrom
limadog9:gh-131837-contextvar-lifetime-docs
Closed

limadog9 wants to merge 1 commit into
python:mainfrom
limadog9:gh-131837-contextvar-lifetime-docs

Conversation

limadog9 commented Oct 20, 2026 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

Explain why creating context variables in closures can extend their lifetimes: a reachable Context holds strong references to variables with values set in it. Repeated creation and binding in a long-lived context can accumulate variables.

Keep the recommendation to create variables at module level while describing the actual retention condition instead of saying they cannot be properly garbage collected.

Fixes #131837.

Validation:

  • Used a weak-referenceable default value to confirm retention by a reachable context, collection after discarding the context, and collection after resetting the variable to its unset state.
  • Full HTML documentation build with warnings treated as errors.
  • Sphinx lint and patchcheck.

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35258704 | 📁 Comparing 20a4450 against main (6044c62)

  🔍 Preview build  

1 file changed
± library/contextvars.html

picnixz commented Oct 23, 2026

Copy link
Copy Markdown
Member

The issue has no clear consensus on what to do (remove warning or change it). Let maintainers decide hwo to proceed later.

picnixz closed this Oct 23, 2026
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

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Improve ContextVar in closures documentation

2 participants


Back | FazBrowse Home | New Git URL