Sobes.tech
Junior — Senior

Order of output of numbers in asyncio coroutine

livecode

Task condition

Determine the order in which the numbers will appear in the console when running the following Python code.

# asyncio / multiprocessing / threading

async def coroutine_a():
    await asyncio.sleep(1000000)
    print('1')

async def coroutine_b():
    await asyncio.sleep(1)
    print('2')

async def run_all():
    await coroutine_a()
    print('3')
    await coroutine_b()

asyncio.run(run_all())