When running the code with await asyncio.sleep(1) below:
import asyncio
async def test1():
for _ in range(0, 3):
print("Test1")
await asyncio.sleep(1) # Here
async def test2():
for _ in range(0, 3):
print("Test2")
await asyncio.sleep(1) # Here
async def test3():
for _ in range(0, 3):
print("Test3")
await asyncio.sleep(1) # Here
async def call_tests():
await asyncio.gather(test1(), test2(), test3())
asyncio.run(call_tests())
test1(), test2() and test3() are run alternately sleeping 1 second each time as shown below:
Test1
Test2
Test3
Test1
Test2
Test3
Test1
Test2
Test3
Now, I want to run them alternately without sleeping but if I remove await asyncio.sleep(1) from them:
# ...
async def test1():
for _ in range(0, 3):
print("Test1")
# await asyncio.sleep(1)
async def test2():
for _ in range(0, 3):
print("Test2")
# await asyncio.sleep(1)
async def test3():
for _ in range(0, 3):
print("Test3")
# await asyncio.sleep(1)
# ...
They are run serially as shown below:
Test1
Test1
Test1
Test2
Test2
Test2
Test3
Test3
Test3
So, how can I run them alternately without sleeping?