-
-
Notifications
You must be signed in to change notification settings - Fork 367
Description
[Edit: This issue started as a discussion of the API for cancel scope shielding, motivated by @merrellb using it to catch Cancelled
errors and do clean up activities like sending "goodbye" messages in #143, but then morphed into a more general discussion of how trio could help users implement "graceful shutdown" functionality in general, so let's make it the standard issue for that. Original text follows. – @njsmith]
The documentation suggests assigning a cancel scope and setting shield as two separate steps:
with move_on_after(CLEANUP_TIMEOUT) as cleanup_scope:
cleanup_scope.shield = True
await conn.send_goodbye_msg()
However trio.open_cancel_scope
has a shield
argument and it seems like it would also make sense with the convenience functions (trio.move_on_after, trio.move_on_at, trio.fail_after and trio.fail_at
). eg:
with move_on_after(CLEANUP_TIMEOUT, shield=True):
await conn.send_goodbye_msg()
I would be happy to make the pull-request if this change makes sense.