Question from the Python test

Waiting for validation

What does the variable tg represent in the first_function and within the context of the main function in the code below that uses asyncio.TaskGroup?

import asyncio

async def second_function():
    for _ in range(5):
        print('Second function iteration')
        await asyncio.sleep(1)


async def first_function(tg: asyncio.TaskGroup):
    for _ in range(5):
        tg.create_task(second_function())
        print('First function iteration')
        await asyncio.sleep(5)


async def main():
    async with asyncio.TaskGroup() as tg:
        task1 = tg.create_task(first_function(tg))
        await task1


asyncio.run(main())
Author: John PendenqueStatus: Waiting for validationQuestion not yet passed
0
Community EvaluationsNo one has reviewed this question yet, be the first!