[Stackless] Ex-lurker (or re: One-way channel pairs)

Isaac ishnigarrab at earthlink.net
Sun Feb 8 00:16:14 CET 2004

Hey, this is Isaac and I've been lurking for a while quite a while 
now... I think it's time to post something (I hate being a leech)...

Anyways, in response to a doc string in Orens channel.close method 
("...will be raised for all receivers, not just one!"):

I'm still not entirely keen on how exactly things work under the hood, 
but I was thinking a good way to accomplish this, is that when receive 
stumbles upon an ExceptionWrapper'd message, it should loop on that 
exception for each receive() call until something like c.clear_exception 
is called (i.e. the code below). One thing to keep in mind is that this 
implies that sending an excpetion will wake up all tasklets pending in 
the receive() queue, and (it they're looping of course) cause them to 
cycle on the same excpetion endlessly until someone actually clears it. 
That is, unless you want to try to keep track of exactly who is 
listening, and when/what they receive... Again, I'm not sure how hard 
that would be to implement as I'm unfamiliar with the code.

Acme Repeating Exceptions
Guaranteed to explode over and over again!
import stackless as st

mychan = st.channel()

exc_times = 0
def f(ch, n):
    global exc_times
    while 1: # Or "for msg in ch" if iteration is implemented
          print ch.receive, n # or "print msg, n" per above
       except Exception, e:
          print e, n
          exc_times += 1
          if exc_times == 4:
             print 'clearing', n
ta1 = st.tasklet(f)(mychan, 1).run()
ta2 = st.tasklet(f)(mychan, 2).run()

map(mychan.send, __import__("string").letters[:4])
mychan.send_exception(Exception, 'catch!')

# Output:
# a 1
# b 2
# c 1
# d 2
# catch! 1
# catch! 2
# catch! 1
# catch! 2
# clearing 1
# done 2

Stackless mailing list
Stackless at stackless.com

More information about the Stackless mailing list