Hello everyone,<br>     as a few knows here, I&#39;m working heavily with PyPy&#39;s &quot;stackless&quot; module for my Master degree project to make it more distributed. Since I started to work full time on this project I&#39;ve encountered a few bugs (mostly related to pickling of tasklets) and missing implementation details in the module. The latest problem I&#39;ve encountered is to be able to detect when tasklet.kill() is called, within the tasklet being killed. With Stackless CPython, TaskletExit is raised and can be caught but this part wasn&#39;t really implemented in PyPy&#39;s stackless module. Since the module is implemented on top of coroutines and since coroutine.kill() is called within tasklet.kill(), the exception thrown by the coroutine implementation needs to be caught. Here&#39;s the problem:<br>
<br><a href="http://codespeak.net/pypy/dist/pypy/doc/stackless.html#coroutines">http://codespeak.net/pypy/dist/pypy/doc/stackless.html#coroutines</a><br><ul><li><p class="first"><tt class="docutils literal"><span class="pre">coro.kill()</span></tt></p>

<blockquote>
<p>Kill <tt class="docutils literal"><span class="pre">coro</span></tt> 
by sending an exception to it.  (At the moment, the
exception is not visible to app-level, which means that you cannot
catch it, and that <tt class="docutils literal"><span class="pre">try:</span>
 <span class="pre">finally:</span></tt> clauses are not honored.  This
will be fixed in the future.)</p></blockquote></li></ul>The exception is not thrown at app level and a coroutine dies silently. Took a look at the code and I&#39;ve been able to expose a CoroutineExit exception to app level on which I intend implementing TaskletExit correctly. I&#39;m also able to catch the exception as expected but the code is not yet complete. <br>
<br>Right now, I have a question on how to expose correctly the CoroutineExit and TaskletExit exceptions to app level. Here&#39;s what I did:<br><br>W_CoroutineExit = _new_exception(&#39;CoroutineExit&#39;, W_Exception, &#39;Exit requested...&#39;)<br>
<br>class AppCoroutine(Coroutine): # XXX, StacklessFlags):<br><br>    def __init__(self, space, state=None):<br>        # Some other code here<br>        <br>        # Exporting new exception to __builtins__ and &quot;exceptions&quot; modules<br>
        self.w_CoroutineExit = space.gettypefor(W_CoroutineExit)<br>        space.setitem(<br>                      space.exceptions_module.w_dict, <br>                      space.new_interned_str(&#39;CoroutineExit&#39;), <br>
                      self.w_CoroutineExit) <br>        space.setitem(space.builtin.w_dict, <br>                      space.new_interned_str(&#39;CoroutineExit&#39;), <br>                      self.w_CoroutineExit)<br><br clear="all">
I talked about this on #pypy (IRC) but people weren&#39;t sure about exporting new names to __builtins__. On my side I wanted to make it look as most as possible as how Stackless CPython did it with TaskletExit, which is directly available in __builtins__. This would make code compatible with both Stackless Python and PyPy&#39;s stackless module. Also, exporting names this way would only make them appear in __builtins__ when the &quot;_stackless&quot; module is enabled (pypy-c built with --stackless). <br>
<br>What are your opinions about it? (Maciej, I already know about yours! ;)<br><br>Thank you very much,<br><br>Gabriel (WildChild)<br><br>-- <br>Gabriel Lavoie<br><a href="mailto:glavoie@gmail.com">glavoie@gmail.com</a><br>