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!
8
Why is the output of the following code undefined?
```
def f(n):
return n + 1
f(n)
```5
What is the output of the following code?
```
import asyncio
async def read_data():
with open('data.txt', 'r') as f:
data = f.read()
return data
async def main():
data = await read_data()
print(data)
if __name__ == '__main__':
asyncio.run(main())
```4
Write a Python code that will wait for 40 seconds.5
Change the value of a nested list element in Python5
In Python, what is the output of the following code? `valueA = 10; valueB = 10; valueA is valueB`4
Python: Decorator that prevents the creation of an instance of a class5
Write a Python program to open a file in binary mode and write a string to it.