The following code outputs as follows:
1 sec delay, print \"1\",
1 sec delay, print \"2\",
1 sec delay, print \"1\",
1 sec delay, print \"2\"
Looking at the desired output, it seems that the goal is to leave the individual iteration as it is - i.e. run first and second sequentially - but execute both loop iterations in parallel.
Assuming you only want to modify main(), it could be achieved like this:
async def main():
async def one_iteration():
result = await first()
print(result)
result2 = await second()
print(result2)
coros = [one_iteration() for _ in range(2)]
await asyncio.gather(*coros)
Instead of iterating in sequence, the above creates a coroutine for each iteration task, and uses asyncio.gather to execute all the iterations in parallel.
Note that simply creating a coroutine doesn't start executing it, so a large number of coros won't block the event loop.