the underlying concept that drives this programming technique is the fact that the yield statement in generator or coroutine function suspends the execution of the function until it is later resumed with next(or send(operation this makes it possible to cooperatively multitask between set of generator functions using scheduler loop here is an example that illustrates the ideadef foo()for in xrange( )print(" ' foo %dnyield def bar()for in xrange( )print(" ' bar %dnyield def spam()for in xrange( )print(" ' spam %dnyield create and populate task queue from collections import deque taskqueue deque(taskqueue append(foo()add some tasks (generatorstaskqueue append(bar()taskqueue append(spam()run all of the tasks while taskqueueget the next task task taskqueue pop(tryrun it to the next yield and enqueue next(tasktaskqueue appendleft(taskexcept stopiterationtask is done pass it is uncommon for program to define series of cpu-bound coroutines and schedule them as shown insteadyou are more likely to see this technique used with / bound taskspollingor event handling an advanced example showing this technique is found in the select module section of "network programming and sockets lib fl ff