[Python-Dev] Re: [Stackless] comments on PEP 219

Christian Tismer tismer at tismer.com
Wed Mar 14 10:39:17 CET 2001


Greg Ewing wrote:

<snip>

> Suppose I'm building an IDE and I want a button which spawns
> a microthread to execute the user's code. The thread doesn't
> make any GUI calls itself, but it's spawned from inside a
> callback, which, if I understand correctly, will be impossible.

This doesn't need to be a problem with Microthreads.
Your IDE can spawn a new process at any time. The
process will simply not be started until the interpreter recursion is
done. I think this is exactly what we want.
Similarily the __init__ situation: Usually you want
to create a new process, but you don't care when it
is scheduled, finally.

So, the only remaining restriction is: If you *force* the
system to schedule microthreads in a recursive call, then
you will be biten by the first uthread that returns to
a frame which has been locked by a different interpreter.

It is pretty fine to create uthreads or coroutines in
the context of __init__. Stackless of course allows
to re-use frames that have been in any recursion. The
point is: After a recrusive interpreter is gone, there
is no problem to use its frames.
We just need to avoid to make __init__ the working
horse, which is bad style, anyway.

> > The one comparable situation
> > in normal Python is crossing threads in callbacks. With the
> > exception of a couple of complete madmen (doing COM
> > support), everyone else learns to avoid the situation.
> 
> But if you can't even *start* a thread using a callback,
> how do you do anything with threads at all?

You can *create* a thread using a callback. It will be started
after the callback is gone. That's sufficient in most cases.

ciao - chris

-- 
Christian Tismer             :^)   <mailto:tismer at tismer.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Kaunstr. 26                  :    *Starship* http://starship.python.net/
14163 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     where do you want to jump today?   http://www.stackless.com/
_______________________________________________
Stackless mailing list
Stackless at starship.python.net
http://starship.python.net/mailman/listinfo/stackless



More information about the Stackless mailing list