Sobes.tech
Junior — Senior

Order of execution and passing arguments in asyncio

livecode

Task condition

Analyze the order in which messages are output and what values are passed between coroutines. Determine what value will be received in the data parameter of the test_2() function in the given example. Check whether the comment under the code matches the actual output order.

# asyncio / multiprocessing / threading

async def test_1():
    data = await asyncio.sleep(10000000)
    print('1')
    return data

async def test_2(data):
    await asyncio.sleep(1, extra=data)
    print('2')

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

asyncio.run(main())