Skip to content
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

Add the concept of a tree variable (TreeVar) #1543

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

oremanj
Copy link
Member

@oremanj oremanj commented May 23, 2020

TreeVars are like ContextVars except that their initial value in new tasks is determined differently: they are inherited from the new task's parent nursery rather than from its spawner. #1523 has some discussion of the possible uses.

Fixes #1523

@oremanj oremanj requested a review from njsmith May 23, 2020 02:45
@codecov
Copy link

codecov bot commented May 23, 2020

Codecov Report

Merging #1543 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff            @@
##           master    #1543    +/-   ##
========================================
  Coverage   99.70%   99.71%            
========================================
  Files         111      111            
  Lines       14035    14175   +140     
  Branches     1084     1090     +6     
========================================
+ Hits        13994    14134   +140     
  Misses         27       27            
  Partials       14       14            
Impacted Files Coverage Δ
trio/__init__.py 100.00% <ø> (ø)
trio/_core/__init__.py 100.00% <100.00%> (ø)
trio/_core/_local.py 100.00% <100.00%> (ø)
trio/_core/_run.py 99.77% <100.00%> (+<0.01%) ⬆️
trio/_core/tests/test_local.py 100.00% <100.00%> (ø)

@oremanj oremanj changed the title Add the concept of a scope variable (ScopeVar) Add the concept of a tree variable (TreeVar) Jun 1, 2020
oremanj added a commit to oremanj/tricycle that referenced this pull request Jun 5, 2023
A TreeVar acts like a context variable that is inherited at nursery creation time (and then by child tasks of that nursery) rather than at task creation time. They are useful for providing 'ambient' access to a resource that is tied to an `async with` block in the parent task, such as an open file or trio-asyncio event loop.

Prior art: python-trio/trio#1543 (never made it into mainline Trio). The implementation without Trio core support is somewhat less efficient, but still workable.
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.

Idea: TreeVar (context variables that follow stack discipline)
1 participant