[Stackless] Stackless and tracing (for debugger)

Richard richard at ccpgames.com
Wed Apr 26 19:06:56 CEST 2006


On 4/26/06, Harry Kalogirou <harkal at sylphis3d.com> wrote:
> Hmmm.. I really don't get how the wrapping thing is possible.. The trace
> functions are per OS-thread in python.

Yes, and Stackless bypasses that and makes them per-tasklet.

> My main loop is something like:
>
> while(1){
>         PyStackless_RunWatchdog(1000000);
> }
>
> The c_tracefunc reset happens inside the PyStackless_RunWatchdog()
> function.
> How do I get to set the trace function in a tasklet?

Wrap all callables that are put into tasklets so when they are first
executed, your code will get executed first, installing the tracefunc.

>>> import stackless
>>> tasklet = stackless.tasklet
>>> def new_call(self, *args, **kwargs):
...     f = self.tempval
...     def new_f(old_f, args, kwargs):
...         print "wrapper.start", args, kwargs
...         old_f(*args, **kwargs)
...         print "wrapper.end"
...     self.tempval = new_f
...     tasklet.setup(self, f, args, kwargs)
...
>>> tasklet.__call__ = new_call
>>>
>>> def test(*args, **kwargs):
...     print "test.enter", args, kwargs
...     stackless.schedule()
...     print "test.exit"
...
>>> tasklet(test)(1,2,3, x=1, y=2, z=3)
>>> stackless.run()
wrapper.start (1, 2, 3) {'y': 2, 'x': 1, 'z': 3}
test.enter (1, 2, 3) {'y': 2, 'x': 1, 'z': 3}
test.exit
wrapper.end
>>>

This is how I would do it anyway.  But I imagine you are going to
be doing it in C++.

Hope this helps,
Richard.

_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless



More information about the Stackless mailing list