[Python-Dev] microthreading vs. async io

Josiah Carlson jcarlson at uci.edu
Thu Feb 15 09:06:30 CET 2007


"Martin v. Löwis" <martin at v.loewis.de> wrote:
> 
> dustin at v.igoro.us schrieb:
> > Asyncore *only* implements asynchronous IO -- any "tasks" performed in
> > its context are the direct result of an IO operation, so it's hard to
> > say it implements cooperative multitasking (and Josiah can correct me if
> > I'm wrong, but I don't think it intends to).
> 
> I'm trying to correct you: By your definition, asyncore implements
> cooperative multi-tasking. You didn't define 'task', but I understand
> it as 'separate activity'. With asyncore, you can, for example, run
> a web server and an IRC server in a single thread, as separate tasks,
> and asyncore deals with the scheduling between these tasks.
> In your terminology, it is based on continuations: the chunk you specify
> is the event handler.
> 
> Indeed, asyncore's doc string starts with
> 
> # There are only two ways to have a program on a single
> # processor do "more than one thing at a time".
> 
> and goes on suggesting that asyncore provides one of them.

Well, when asyncore was written, it probably didn't have coroutines,
generator trampolines, etc., what we would consider today, in this
particular context, "cooperative multithreading".

What that documentation /should/ have said is...

# There are at least two ways to have a program on a single
# processor do "more than one thing at a time".

Then go on to describe threads, a 'polling for events' approach like
asyncore, then left the rest for someone else to add later.  I'll add it
as my first patch to asyncore.

 - Josiah



More information about the Python-Dev mailing list