Overview:
-
The asyncio.sleep() method suspends the execution of a coroutine.
-
Coroutines voluntarily yield CPU leading to co-operative multitasking through the await keyword.
Example:
# Example Python program that uses the asyncio.sleep() # Coroutine that prints odd numbers # Coroutine that prints even numbers # Coroutine that awaits on tasks printOdd and printEven await asyncio.wait([oddTask, evenTask]) # Create a new event loop and run the tasks |
Output:
1 2 3 4 5 6 7 8 9 |