Sobes.tech
Junior — Senior

Print order with sequential await in asyncio

livecode

Task condition

Determine the order in which the numbers will be output when running the following script.

# asyncio / multiprocessing / threading

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

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

async def main():
    await test_1()
    print('3')
    await test_2()

asyncio.run(main())