In the Section “Concurrency using asyncio” we have the following code:
import asyncio
import time
async def func1():
for i in range(5):
print('Inside Func1')
await asyncio.sleep(1)
async def func2():
for i in range(5):
print('Inside Func2')
await asyncio.sleep(0.8)
start = time.time()
async_tasks = asyncio.gather(func1(), func2())
asyncio.get_event_loop().run_until_complete(async_tasks)
end = time.time()
print('Asyncio took {} seconds'.format(round(end-start),2))
Running the code prints “Asyncio took 5 seconds”.
Why isn’t it 9 seconds (5x1 + 5x0.8) ?