It gets moved to the end. The approximate algorithm is: (1) Determine the list of callbacks that are ready right now (2) Run each callback in turn (3) Sleep (if needed) until more callbacks are ready (4) Go to (1)
When you yield or sleep(0) during step (2), your coroutine is placed in a new queue and isn't processed until we hit (1) again. The actual code is more convoluted but this is the essence. Check out this for-loop, which represents step (2): https://github.com/python/asyncio/blob/master/asyncio/base_events.py#L1244 On Sun, Oct 25, 2015 at 11:58 AM, Imran Geriskovan < [email protected]> wrote: > Does bare yield or asyncio.sleep(0) put the coroutine > at the END of execution queue of event loop, so that > other already waiting coroutines takes precedence? > Is this the case? > > If not, what is the policy for execution order? > FIFO, random, ...? > > Regards, > Imran > -- --Guido van Rossum (python.org/~guido)
