-
-
Notifications
You must be signed in to change notification settings - Fork 8
Warn on finally: cancel_scope.cancel() #365
Copy link
Copy link
Open
Labels
new rulenew rule ideanew rule ideapostponedLow priority, blocked, or similar.Low priority, blocked, or similar.
Description
Like async102 and async120, this is to address the concerns discussed in python-trio/trio#455. (also: should the rules docs link there?)
with CancelScope() as scope:
try:
... # whatever sync and async code here
finally:
scope.cancel()
# You'd hope this just stops any ongoing work, but it swallows exceptions too!In most cases the solution is simply to scope.cancel() without the try/finally block - structured concurrency means we reliably clean up on exceptions anyway. For some, the cancel scope is entirely unnecessary, and you could call e.g. recv_chan.close() instead of cancelling.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
new rulenew rule ideanew rule ideapostponedLow priority, blocked, or similar.Low priority, blocked, or similar.