[Tutor] I m trying to understand why we need Co-routines

Alan Gauld alan.gauld at btinternet.com
Wed Feb 7 17:35:55 CET 2007

"anil maran" <anilmrn at yahoo.com> wrote

> Yesterday I spoke to an employee of yahoo egroups and
> he was explaining that they used coroutines to send mails in egroups
> because each thread was 2mb in size...
> Can you point me to resources on how to use co-routines in python
> or if you have code samples it would be great

A coroutine is just a generic computing science term for
any technique that runs multiple tasks 'concurrently' within a
single process.

The normal way to do that nowadays is using threads, which
are supported in Python. Other approaches which are also
considered to be coroutines include generators (which allow
a task to be 'paused' in mid flow for example) and action lists
(lists of functions which are executed in turn by a top level
function. Common in real-time and embedded apps where
precise control of schedulling is needed). Coroutine programming
was common in the days of assembler where multi tasking
OS's and threading did not exist.

Interestingly the examples given in Wikipedia are closest to
the python generator example but those are not the most common
approach to coroutines in my experience...


Alan G 

More information about the Tutor mailing list