[Stackless] A select() method, stackless.run() Re: Stackless Digest, Vol 23, Issue 4

Christian Tismer tismer at stackless.com
Tue Dec 20 22:38:20 CET 2005

Hi Andrew,


> Okay, I have a naive question. In my example, I have
> the form:
> a = tasklet()()
> b = tasklet()()
> c = tasklet()()
> .
> .
> .
> print "---begin--"
> stackless.run() # I guess stackless.schedule() would work too

No, it would not. stackless.run() runs until there is no longer
any runnable tasklet but main. schedule() would just leave
main and run the tasklets in turn, but you don't know when
you get back to main and if things are done.

> print "--finish--"
> I am assuming that in this form, stackless.run() returns after
> all tasklets are finished. So in a sense it also acts as a 
> barrier synchroniser. Would this be safe to assume?

Yes, almost. There are chances that main gets revived earlier
if a tasklet exposes an uncaught exception, of course.
This is by intent, to make you write exception handlers :-)

> I guess I would place a debug or an assert after a
> run()?
> stackless.run()
> if __debug__:
>    if stackless.getruncount() != 1 :
>       raise _______

Sure you can.

> if __debug__:
>    for channel in channelsL
>        if channel.balance != 0:
>           raise

You can do this, too. Note that this has different semantics,
because whether there are blocked tasklets in your channels
is due to the semantics of your program. stackless.run()
cannot know about this.

>> I think we can make things easier by thinking of a construct
>> that allows to wait on more than one channel at a time.
>> This can probably be written on top of the builtin stuff.
>> It needs a bit of abstraction, of course.
> A method that looks similar to the BSD Socket select() function
> springs to mind. Handles both reading and writing and
> perhaps opens the door to a smoother integration of IO?

Well, can be used. I'd prefer to think of PAR and ALT semantics
of CSP. Maybe you'd like to check that example from Tom Locke,
who posted CSP examples on this list?

See http://www.stackless.com/pipermail/stackless/2004-January/001062.html

ciao - chris

Christian Tismer             :^)   <mailto:tismer at stackless.com>
tismerysoft GmbH             :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9A     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
work +49 30 802 86 56  mobile +49 173 24 18 776  fax +49 30 80 90 57 05
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?   http://www.stackless.com/

Stackless mailing list
Stackless at stackless.com

More information about the Stackless mailing list