I have been building an interactive debugger for stackless python and I have had to use a bit of a hacky way to be able to trace worker tasklets that were started before the trace function was set.<br><br>To be able to enable tracing for the worker tasklets, you have to hook into the schedule_callback and set the f_trace of the frame manually when the tasklet is being resumed.
<br>This is also something you needed to do in python 2.3, but you only had to set the tracing function once.<br><br>Now you need to call sys.settrace within the running tasklet and manually set the f_trace for the tasklet.
<br><br>Is this a bug or a design flaw?<br><pre><b><span class="code-lang">import</span></b> sys<br><b><span class="code-lang">import</span></b> stackless<br><br><b><span class="code-lang">def</span></b> <b><span class="code-func">
contextDispatch</span></b>( prev, next ):<br>    <b><span class="code-lang">if</span></b> <b><span class="code-lang">not</span></b> prev: <i><span class="code-comment">#Creating next<br></span></i>        <b><span class="code-lang">
print &quot;Creating &quot;, next # I never see this print out</span></b><br>    <b><span class="code-lang">elif</span></b> <b><span class="code-lang">not</span></b> next: <i><span class="code-comment">#Destroying prev<br>
</span></i>        <b><span class="code-lang"><span style="font-weight: bold;">print &quot;Destroying &quot;, prev # I never see this print out either</span></span></b><br>    <b><span class="code-lang">else</span></b>:<br>
        <i><span class="code-comment"># Prev is being suspened<br></span></i>        <i><span class="code-comment"># Next is resuming<br></span></i>        <i><span class="code-comment"># When worker tasklets are resuming and have not been 
<br></span></i>        <i><span class="code-comment"># set to trace, we make sure that they are tracing before they run again<br></span></i>        <b><span class="code-lang">if</span></b> <b><span class="code-lang">not</span>
</b> next.frame.f_trace:<br>            <i><span class="code-comment"># We might allready be tracing so ...</span></i><i><span class="code-comment"><br></span></i>            sys.call_tracing(next.settrace,(traceDispatch,))
<br><br>stackless.set_schedule_callback( contextDispatch  )<br><b><span class="code-lang"></span></b><i><span class="code-comment"></span></i><i><span class="code-comment"><br></span></i><b><span class="code-lang">def</span>
</b> <b><span class="code-func">__call__</span></b>(self, *args, **kwargs):<br>     f = self.tempval<br>     <b><span class="code-lang">def</span></b> <b><span class="code-func">new_f</span></b>(old_f, args, kwargs):<br>         
sys.settrace(traceDispatch)<br>         old_f(*args, **kwargs)<br>         sys.settrace(None)<br>     self.tempval = new_f<br>     stackless.tasklet.setup(self, f, args, kwargs)<br><br><b><span class="code-lang">def</span>
</b> <b><span class="code-func">settrace</span></b>( self, tb ):<br>    self.frame.f_trace = tb<b><span class="code-lang"></span></b>   <br>    sys.settrace( tb )<br><br>stackless.tasklet.__call__ = __call__<br>stackless.tasklet.settrace
 = settrace<br><br>Best regards,<br><br>Vilhelm Páll Sćvarsson<br></pre><br>