<div>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. </div>
<div> </div>
<div>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++?<br>
<br></div>
<div class="gmail_quote">2009/12/29 Kristján Valur Jónsson <span dir="ltr"><<a href="mailto:kristjan@ccpgames.com">kristjan@ccpgames.com</a>></span><br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div lang="IS" vlink="purple" link="blue">
<div>
<div class="im">
<p class="MsoNormal">producers[int(ind)] = stackless.tasklet(producer)(ind,sleeptime)</p>
<p class="MsoNormal"> </p></div>
<p class="MsoNormal">this line will create a tasklet bound to the „producer“ callable, bind it to (ind, sleeptime) and return it to the „producers“ list.</p>
<p class="MsoNormal">Setting up a tasklet simply returns the same tasklet object, exactly so that you can do the following:</p>
<div class="im">
<p class="MsoNormal">producers<span lang="EN-US">[int(ind)] = stackless.tasklet(producer)</span></p></div>
<p class="MsoNormal"><span lang="EN-US">producers[int(ind)](ind, sleeptime)</span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US">in one line.</span></p>
<p class="MsoNormal"><span lang="EN-US">There is no “return value” from the tasklet in play here.</span></p>
<p class="MsoNormal"><span lang="EN-US">in short:</span></p>
<p class="MsoNormal"><span lang="EN-US">stackless.tasklet.__call__(self, *args)</span></p>
<p class="MsoNormal"><span lang="EN-US">returns self.</span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US">K</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<div style="BORDER-BOTTOM: medium none; BORDER-LEFT: blue 1.5pt solid; PADDING-BOTTOM: 0cm; PADDING-LEFT: 4pt; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; BORDER-RIGHT: medium none; PADDING-TOP: 0cm">
<div>
<div style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0cm; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<p class="MsoNormal"><b><span style="FONT-SIZE: 10pt" lang="EN-US">From:</span></b><span style="FONT-SIZE: 10pt" lang="EN-US"> <a href="mailto:stackless-bounces@stackless.com" target="_blank">stackless-bounces@stackless.com</a> [mailto:<a href="mailto:stackless-bounces@stackless.com" target="_blank">stackless-bounces@stackless.com</a>] <b>On Behalf Of </b>A M<br>
<b>Sent:</b> 29. desember 2009 09:09<br><b>To:</b> <a href="mailto:stackless@stackless.com" target="_blank">stackless@stackless.com</a><br><b>Subject:</b> [Stackless] Calling a tasklet with a return value with the C API</span></p>
</div></div>
<div>
<div></div>
<div class="h5">
<p class="MsoNormal"> </p>
<div>
<p class="MsoNormal">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.</p>
</div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">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 (<a href="http://stacklessexamples.googlecode.com/svn/trunk/examples/producerConsumerTextmode.py" target="_blank">http://stacklessexamples.googlecode.com/svn/trunk/examples/producerConsumerTextmode.py</a>):</p>
</div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">-----------</p></div>
<div>
<p class="MsoNormal">def launch_p (ind,sleeptime): # Launches and initializes the producers lists<br> producers.append(int(ind))<br> p_counter.append(0)<br> producers[int(ind)] = stackless.tasklet(producer)(ind,sleeptime)<br>
------------</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">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.</p>
</div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">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?</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">Thanks</p></div>
<div>
<p class="MsoNormal">Andy</p></div>
<div>
<p class="MsoNormal"> </p></div>
<div>
<p class="MsoNormal">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? -> <a href="http://www.disinterest.org/resource/stackless/2.6.4-docs-html/c-api/index.html" target="_blank">http://www.disinterest.org/resource/stackless/2.6.4-docs-html/c-api/index.html</a></p>
</div></div></div></div></div></div></blockquote></div><br>