Skip to content
Advertisement

python asyncio.create_task tasks exiting earlier than expected?

I have the following code:

JavaScript

It outputs:

JavaScript

Notice that world isn’t printed anywhere. Why is the output we see being produced? I was expecting:

JavaScript

Because I thought that the asyncio.sleep(i) calls would yield execution to the event loop, at which point the event loop would reschedule them after their respective wait times. Clearly I am misunderstanding. Can someone explain?

Advertisement

Answer

Found a much simpler solution than the one provided by @eyllanesc here. Turns out there is a function that implements it

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement