First, you have to figure out how to do it purely in python. There is no automatic "wait" semantic built in. The return value from the toplevel tasklet function just vanishes.
The typical way is to create a channel: c = stackless.channel() def func(*args): ... c.send(result) return "this result string will vanish" stackless.tasklet(func)(arg1, ...) result = c.receive() K From: A M [mailto:[email protected]] Sent: 29. desember 2009 19:50 To: Kristján Valur Jónsson Cc: [email protected] Subject: Re: [Stackless] Calling a tasklet with a return value with the C API Yes, I obviously got so excited in thinking I found a good example of what I was interested in knowing, that I didn't think it through carefully. PyTasklet_New() returns a PyTaskletObject*, so I already knew how to recreate that particular line of python. However, that aside, is it at all possible to acquire a result value from a function executed as a tasklet using the C API? Let's say you have a function that is acquiring a dict of data from an online database that you want to run as a tasklet, but you need the return value. How is such a thing done purely in C/C++? 2009/12/29 Kristján Valur Jónsson <[email protected]<mailto:[email protected]>> producers[int(ind)] = stackless.tasklet(producer)(ind,sleeptime) this line will create a tasklet bound to the "producer" callable, bind it to (ind, sleeptime) and return it to the "producers" list. Setting up a tasklet simply returns the same tasklet object, exactly so that you can do the following: producers[int(ind)] = stackless.tasklet(producer) producers[int(ind)](ind, sleeptime) in one line. There is no "return value" from the tasklet in play here. in short: stackless.tasklet.__call__(self, *args) returns self. K From: [email protected]<mailto:[email protected]> [mailto:[email protected]<mailto:[email protected]>] On Behalf Of A M Sent: 29. desember 2009 09:09 To: [email protected]<mailto:[email protected]> Subject: [Stackless] Calling a tasklet with a return value with the C API After a few years of scouring the Internet for example code and viewing the very sparse documentation on the subject, I have been able to successfully utilize almost all aspects of the C API with regard to stackless python. I feel pretty comfortable with most all functions declared in stackless_api.h. However, there is one thing I cannot figure out and cannot find an example for anywhere: running a tasklet with the C API that returns a value. Take, for example, this python code from one of the stackless python examples online (http://stacklessexamples.googlecode.com/svn/trunk/examples/producerConsumerTextmode.py): ----------- def launch_p (ind,sleeptime): # Launches and initializes the producers lists producers.append(int(ind)) p_counter.append(0) producers[int(ind)] = stackless.tasklet(producer)(ind,sleeptime) ------------ The last line is the one that I have no idea how to recreate. Certainly, creating a tasklet, setting it up, and running it is trivial; however, I cannot for the life of me figure out how you would get a return value with the C API. My initial thought was perhaps the results are sent back on a 'channel'; however, I do not see any documentation that supports that, nor can I find any examples of it. Anyway, can anyone help me out with this? It's keeping me awake at night! If not, can someone give me a contact address for one of the developers of stackless that wrote the C API for it? Thanks Andy ps. By the way, does anyone know why this link indicates that it's the C/C++ API for stackless 2.6.4 but has none of the stackless functions within it? -> http://www.disinterest.org/resource/stackless/2.6.4-docs-html/c-api/index.html
_______________________________________________ Stackless mailing list [email protected] http://www.stackless.com/mailman/listinfo/stackless
