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.
Like async102 and async120, this is to address the concerns discussed in python-trio/trio#455. (also: should the rules docs link there?)
In most cases the solution is simply to
scope.cancel()without thetry/finallyblock - 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.