[Stackless] Re: Stackless API
Oren Tirosh
oren-slp at hishome.net
Tue Feb 3 13:57:42 CET 2004
On Tue, Feb 03, 2004 at 06:50:06AM -0300, Esteban U. Caamano Castro wrote:
> > I gues that raising a bomb on a channels is not the
> > most
> > common action unless you are the roadrunner coyote,
>
> Agreed.
>
> > so maybe it would be most efficient to use a special
> > object as a marker flag? This object could be solely
> > visible
> > to channels.
>
> Yes, this is Tirosh' proposal.
>
> Assume that you have a channel class with no exception
> support whatsoever. You could implement
> exception sending on top of that, like this
>
>
> class CoyoteChannel(stackless.channel):
>
> class __ExceptionWrapper:
> def __init__(self, exc):
> self.exc = exc
>
> def send_exception(self, exc):
> self.send(self.__ExceptionWrapper(exc))
>
> def receive(self):
> o = stackless.channel.receive(self)
> if getattr(o, '__class__', None) is \
> self.__ExceptionWrapper:
> raise o.exc
> else:
> return o
Exactly. Except that it's going to be in C and checking the type can take
about a nanosecond: if (result->ob_type == ExceptionWrapperType). It's even
faster than the current code: if (Py_IsInstance(result, PyExceptionType))
that makes a function call and checks if the object is somehow descended
from Exception. It's ok to check the type directly because this type is not
subclassable or even visible.
Oren
_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless
More information about the Stackless
mailing list