Skip to content

Should aclose() always wrap its contents in a CancelScope(shield=True)? #424

Answered by njsmith
jwodder asked this question in Q&A
Discussion options

You must be logged in to vote

Trio's convention is that:

  • aclose methods must always succeed, regardless of whether they're called in a cancelled context or not
  • if they're called in a cancelled context, they must return promptly (so e.g. skip the Close handshake)
  • otherwise they can do a graceful close if that's appropriate

So if you're using this convention, you don't want to shield the call to aclose, because that denies aclose the ability to tell whether it's supposed to do a graceful shutdown or not. It does require that everyone writing aclose methods follows the rules, though.

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by graingert
Comment options

You must be logged in to vote
1 reply
@jwodder
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants