[Stackless] Retrieving the Return Value of a Stackless Python Tasklet Bound Function?

Lin Luo luolin at ccpgames.com
Wed Jun 23 09:59:35 CEST 2010


Thanks Richard! Your solution definitely helped me solving this problem. :)

Instead of having to compiling the Python code in the C string, I actually had the leisure to define RunFunctionAndGetResult (well, I changed the name actually :)) inside one of our utility python source file, and from C code I just retrieve the respective PyObject reference, which is then in turn wrapped into a tasklet on the C side!

For channel stuff, I had to use PyChannel_GetQueue to poll the channel if any function running as a tasklet has finished, so they got blocked on it due to trying to put the return value on the channel, since on the C side, everything must not block, and C code would *better* not participate in Stackless tasklet scheduling, even though I know (heard) Stackless can swap C stack perfectly as well, but please, don't block my C code. :)

From: stackless-bounces at stackless.com [mailto:stackless-bounces at stackless.com] On Behalf Of Andrew Tutt
Sent: Wednesday, June 23, 2010 3:13 PM
To: The Stackless Python Mailing List
Subject: Re: [Stackless] Retrieving the Return Value of a Stackless Python Tasklet Bound Function?

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))

That was precisely the suggestion I would have made, but I was not sure it would be right. Gives me a bit more confidence when it comes to answering future questions!

On Tue, Jun 22, 2010 at 11:16 PM, Richard Tew <richard.m.tew at gmail.com<mailto:richard.m.tew at gmail.com>> wrote:
On Tue, Jun 22, 2010 at 11:37 PM, Lin Luo <luolin at ccpgames.com<mailto:luolin at ccpgames.com>> 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
Stackless at stackless.com<mailto:Stackless at stackless.com>
http://www.stackless.com/mailman/listinfo/stackless

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.stackless.com/pipermail/stackless/attachments/20100623/65f98eb9/attachment.htm>


More information about the Stackless mailing list