Hello ClockΒΆ

Example illustrating how to schedule two coroutines to run concurrently. They run for ten minutes, during which the first coroutine is scheduled to run every second, while the second is scheduled to run every minute.

The function asyncio.gather is used to schedule both coroutines at once.

import asyncio

async def print_every_minute():
    "Print minutes for ten minutes"
    for i in range(10):
        await asyncio.sleep(60)
        print(i, 'minute')

async def print_every_second():
    "Print seconds for ten minutes"
    for i in range(10 * 60):
        for i in range(60):
            print(i, 's')
            await asyncio.sleep(1)

loop = asyncio.get_event_loop()