Even better, you can do this:
def RunFunctionAndGetResult(chan, func, *args, **kwargs):
try:
chan.send(func(*args, **kwargs))
except Exception, e:
import sys
chan.send_exception(*sys.exc_info()[:2])
thus passing exception information onwards. The good thing about using a
channel is that the waiting task can choose wheter it blocks for the tasklet,
or just polls it. Otherwise, you could use some external structure, such as a
list, to do this. The channel will also magically re-raise the exception.
One wart with this is the need to use exc_info. This is because of the
arguments that send_exception takes. It would be better (and I will change
this) if send_exception could take the same arguments as the "raise" keyword.
That way, one could use
chan.send_exception(e) #just send the same exception instance onward
chan.send_exception(*sys.exc_info()) #send full info, including traceback.
K
> -----Original Message-----
> From: [email protected] [mailto:stackless-
> [email protected]] On Behalf Of Richard Tew
> Sent: 22. júní 2010 21:17
> To: The Stackless Python Mailing List
> Subject: Re: [Stackless] Retrieving the Return Value of a Stackless
> Python Tasklet Bound Function?
>
> On Tue, Jun 22, 2010 at 11:37 PM, Lin Luo <[email protected]> wrote:
> > the caller. But I have yet to see a way to retrieve the return value
> of the
> > bound callable running as a tasklet.
>
> I do not know that there is one.
>
> > important return value to be used later. It seems that writing such a
> > Micromanaging function on the C side is not very feasible, since I
> haven't
>
> The simplest way to do this would be to define the wrapping Python
> function code in C as a string, and to compile it into a function
> object that you can run as a tasklet. An example Python function
> follows, the C part I leave to you.
>
> e.g.
>
> def RunFunctionAndGetResult(chan, func, *args, **kwargs):
> chan.send(func(*args, **kwargs))
>
> Cheers,
> Richard.
>
> _______________________________________________
> Stackless mailing list
> [email protected]
> http://www.stackless.com/mailman/listinfo/stackless
_______________________________________________
Stackless mailing list
[email protected]
http://www.stackless.com/mailman/listinfo/stackless