Real programs must be able to stop waiting: a user closes a connection, a server is slow, a deadline passes. In asyncio, stopping a task is cooperative. The loop raises an error at the task’s current await, and the task has a chance to clean up. This lesson covers cancellation, the rule that you must not swallow it, and the two ways to put a time limit on work.
More lessons in Complete Python Programming