Overview:
-
For a task to be considered cancelled, the coroutine that is wrapped as the Task should have handled and propagated the asyncio.CancelledError.
-
The method cancelled() returns whether a Task has been cancelled or not.
-
The return value is True, if the Task has been cancelled successfully and False otherwise.
Example:
# Example Python program that cancels # A coroutine defintion of order bot # Coroutine that creates the Task
# Create event loop # Set the new loop object to asyncio # Run the asyncio Task |
Output:
Making orders... Making orders... Making orders... Stopping the bot Bot stopped Console has stopped the bot Task has been cancelled:True |