here is the code:
In [168]: async def myTask():
...: await asyncio.sleep(2)
...: print("processing task")
In [168]: async def generator():
...: for i in range(5):
...: asyncio.create_task(myTask())
In [168]: def abcd():
...: t0=time.time()
...: loop=asyncio.get_event_loop()
...: loop.run_until_complete(generator())
...: t1=time.time()
...: print(t1-t0)
Ideally calling abc() should sleep for around 10 seconds(as I have not awaited the asyncio.create_task(myTask())), but the function is getting completed in less than 0.1 secs.
In [167]: abcd()
processing task
processing task
processing task
processing task
processing task
0.0004038810729980469
myTask(). If you try replacingmyTask()withasyncio.sleep(2)directly, you'll get exactly the same behavior. Hmmm...