[Stackless] Video on channels

Johan Carlsson johanc at easypublisher.com
Mon Sep 10 12:24:19 CEST 2007


On 9/9/07, Arnar Birgisson <arnarbi at gmail.com> wrote:
> Hi all,
>
> On 9/9/07, Hallgrimur H. Gunnarsson <hhg at hhg.to> wrote:
> > I watched the same techtalk a while ago and after it I also translated the
> > prime sieve example into stackless python as an exercise. The outcome
> > was a little different from your version, see below (or http://hhg.to/sieve.py).
>
> I did this as an exercise too, but not with channels. Here's my
> version which uses only 2.4 style generators, no stackless needed
> (__main__ part stolen from Hallgrímur):
>
> #!/usr/bin/env python
>
> def counter(i=1):
>     while True:
>         yield i
>         i += 1
>
> def filter(p, r):
>     for x in r:
>         if x % p:
>             yield x
>
> def sieve():
>     c = counter(2)
>     while True:
>         p = c.next()
>         yield p
>         c = filter(p, c)
>
> if __name__ == '__main__':
>     import sys
>     if len(sys.argv) < 2:
>         goal = 100
>     else:
>         goal = int(sys.argv[1])
>
>     s = sieve()
>     for i in xrange(goal):
>         print s.next()
>

In the yield version presented here won't the stack keep growing for
each function call?

In the Stackless version the number of channels keeps growing, right?
Which is the same case as in the Newsqueak version?

(notice I just raise questions, because I haven't thought this through yet :-D)

--
Johan Carlsson
Colliberty Easy Publisher
http://www.easypublisher.com




More information about the Stackless mailing list