It does not provide a means of pausing until cancellation is complete. This is a common requirement. It can be achieved with exception trapping and the use of synchronisation primitives but I thought it worth offering a little syntactic sugar to hide these gory details which are not entirely free from potential bear-traps My asyn library now does this. A typical use-case is as follows:
Code: Select all
import asyn
async def comms(): # Perform some communications task
while True:
await initialise_link()
try:
await do_communications() # Launches Cancellable tasks
except CommsError:
await asyn.Cancellable.cancel_all()
# All sub-tasks are now known to be stopped. They can be re-started
# with known initial state on next pass.