[Stackless] Tracing stackless tasklets.

Vilhelm Sævarsson vilhelmenator at gmail.com
Mon Oct 1 13:38:29 CEST 2007


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.

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.
This is also something you needed to do in python 2.3, but you only had to
set the tracing function once.

Now you need to call sys.settrace within the running tasklet and manually
set the f_trace for the tasklet.

Is this a bug or a design flaw?

*import* sys
*import* stackless

*def* *contextDispatch*( prev, next ):
    *if* *not* prev: *#Creating next
*        *print "Creating ", next # I never see this print out*
    *elif* *not* next: *#Destroying prev
*        *print "Destroying ", prev # I never see this print out either*
    *else*:
        *# Prev is being suspened
*        *# Next is resuming
*        *# When worker tasklets are resuming and have not been
*        *# set to trace, we make sure that they are tracing before
they run again
*        *if* *not* next.frame.f_trace:
            *# We might allready be tracing so ...**
*            sys.call_tracing(next.settrace,(traceDispatch,))

stackless.set_schedule_callback( contextDispatch  )
*****
**def* *__call__*(self, *args, **kwargs):
     f = self.tempval
     *def* *new_f*(old_f, args, kwargs):
         sys.settrace(traceDispatch)
         old_f(*args, **kwargs)
         sys.settrace(None)
     self.tempval = new_f
     stackless.tasklet.setup(self, f, args, kwargs)

*def* *settrace*( self, tb ):
    self.frame.f_trace = tb**
    sys.settrace( tb )

stackless.tasklet.__call__ = __call__
stackless.tasklet.settrace = settrace

Best regards,

Vilhelm Páll Sævarsson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.stackless.com/pipermail/stackless/attachments/20071001/93037b6e/attachment.htm>


More information about the Stackless mailing list