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

[docs] clarify checkpoint semantics for trio.open_nursery #3011

Merged
merged 2 commits into from
Jun 14, 2024

Conversation

jakkdl
Copy link
Member

@jakkdl jakkdl commented Jun 6, 2024

Documents the changes made in #1696 more explicitly.

Copy link

codecov bot commented Jun 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.63%. Comparing base (2741527) to head (d5a196d).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3011   +/-   ##
=======================================
  Coverage   99.63%   99.63%           
=======================================
  Files         120      120           
  Lines       17855    17857    +2     
  Branches     3212     3212           
=======================================
+ Hits        17790    17792    +2     
  Misses         46       46           
  Partials       19       19           
Files Coverage Δ
src/trio/_core/_run.py 99.38% <ø> (ø)

... and 1 file with indirect coverage changes

@@ -102,6 +102,8 @@ them. Here are the rules:
only that one will act as a checkpoint. This is documented
on a case-by-case basis.

* :func:`trio.open_nursery` is a further exception to this rule.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is needed, I think the Partial exception for async context managers block handles this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be overkill, but open_nursery in itself as a context manager doesn't guarantee a full checkpoint on either of entry or exit - so imo it doesn't abide by the special rules in the Partial exception for async context managers block. There's some more discussion around this in #1457

@@ -993,7 +993,8 @@ def open_nursery(
new `Nursery`.

It does not block on entry; on exit it blocks until all child tasks
have exited.
have exited. If no child tasks are running on exit, it will insert a
schedule point (but no cancellation point).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is unique behaviour, maybe it'd be good to add an additional sentence explaining why this is the case - something like "A nursery is never the source of the cancellation exception, it only propagates it from sub-tasks."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually, is that not functionally the same as https://trio.readthedocs.io/en/stable/reference-lowlevel.html#trio.lowlevel.cancel_shielded_checkpoint ?
If so, we can refer to that for a more thorough explanation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think just referring to that builds any kind of intuition for why open_nursery is a special case. In fact I forgot the exact wording/problem that convinced me, but I think it was some message on the gitter (that pushed the old PR to be merged).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a small commit that both refers to cancel_shielded_checkpoint and includes teamspen's blurb on what this implies. Not sure if that also covers @A5rocks comment?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly, but I think docs as is are good enough:tm:

Copy link
Member

@CoolCat467 CoolCat467 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

@CoolCat467 CoolCat467 merged commit 451393a into python-trio:master Jun 14, 2024
28 checks passed
@jakkdl jakkdl deleted the document_nursery_checkpointing branch June 20, 2024 20:08
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.

4 participants