Hello,
I would like to know how can I order a program like this:
import asyncio
async def multi_coro():
async with asyncio.TaskGroup() as tg:
tg.create_task(coro('5'))
print('3-')
tg.create_task(coro('6'))
print('4-')
async def coro(i):
print(i)
await asyncio.sleep(.1)
print(i)
async def main():
async with asyncio.TaskGroup() as tg:
tg.create_task(multi_coro())
print('1-')
tg.create_task(coro('7'))
print('2-')
print('8-')
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(main())
My goal is to get this return:
1-
2-
3-
4-
5
6
7
5
6
7
8-
But the return is:
1-
2-
3-
4-
7
5
6
7
5
6
8-
In use asyncio.gather(), the result is like TaskGroup.
async def gather():
print('3-')
await asyncio.gather(*[coro('4'), coro('5')])
print('6-')
So I would like to know how can I do to call tasks group in multi_coro before to call the second task in the main()
Tanks you.