@@ -8,8 +8,8 @@ Debugging tools, like those used for tracing, are implemented through
88calls to the :func: `sys.settrace ` function. Now, in |CPY |, when
99this has been called any code that runs within the operating system thread
1010is covered by it. In Stackless however, this function only covers the
11- current tasklet. Stackless provides the tasklet attributes
12- :attr: `~tasklet.trace_function ` and :attr: `~tasklet.profile_function ` to
11+ current tasklet. Stackless provides the tasklet attributes
12+ :attr: `~tasklet.trace_function ` and :attr: `~tasklet.profile_function ` to
1313get and set the trace/profile function of a particular tasklet.
1414
1515The debugging related modules, whether :doc: `in the standard library
@@ -19,8 +19,8 @@ In an ideal world, |SLP| might include modified versions of these
1919modules, and patches adding them would be most welcome.
2020
2121If you want working debugging for |SLP |, at this time your best
22- option is to use the `WingWare Python IDE <http://wingware.com >`_
23- or the `Eclipse IDE with the PyDev-Plugin <http://pydev.org >`_.
22+ option is to use the `WingWare Python IDE <http://wingware.com >`_
23+ or the `Eclipse IDE with the PyDev-Plugin <http://pydev.org >`_.
2424Both have gone out of their way to add and support |SLP | development.
2525
2626.. note ::
@@ -36,39 +36,39 @@ Tracing tasklets
3636
3737In order to get debugging support working on a per-tasklet basis, you need to
3838ensure you enable tracing for all tasklets. This can be archived by the
39- schedule callback. This callback sees every task switch. Here is
39+ schedule callback. This callback sees every task switch. Here is
4040a complete example::
4141
4242 from __future__ import absolute_import, print_function
43-
43+
4444 import sys
4545 import stackless
4646 import traceback
47-
48-
47+
48+
4949 class NamedTasklet(stackless.tasklet):
5050 __slots__ = ("name",)
51-
51+
5252 def __init__(self, func, name=None):
5353 stackless.tasklet.__init__(self, func)
5454 if name is None:
5555 name = "at %08x" % (id(self))
5656 self.name = name
57-
57+
5858 def __repr__(self):
5959 return "<tasklet %s>" % (self.name)
60-
61-
60+
61+
6262 class Mutex(object):
63-
63+
6464 def __init__(self, capacity=1):
6565 self.queue = stackless.channel()
6666 self.capacity = capacity
67-
67+
6868 def isLocked(self):
6969 '''return non-zero if locked'''
7070 return self.capacity == 0
71-
71+
7272 def lock(self):
7373 '''acquire the lock'''
7474 currentTasklet = stackless.getcurrent()
@@ -80,7 +80,7 @@ a complete example::
8080 self.queue.receive()
8181 finally:
8282 currentTasklet.set_atomic(atomic)
83-
83+
8484 def unlock(self):
8585 '''release the lock'''
8686 currentTasklet = stackless.getcurrent()
@@ -92,10 +92,10 @@ a complete example::
9292 self.capacity += 1
9393 finally:
9494 currentTasklet.set_atomic(atomic)
95-
95+
9696 m = Mutex()
97-
98-
97+
98+
9999 def task():
100100 name = stackless.getcurrent().name
101101 print(name, "acquiring")
@@ -104,8 +104,8 @@ a complete example::
104104 stackless.schedule()
105105 print(name, "releasing")
106106 m.unlock()
107-
108-
107+
108+
109109 def trace_function(frame, event, arg):
110110 if frame.f_code.co_name in ('schedule_cb', 'channel_cb'):
111111 return None
@@ -114,8 +114,8 @@ a complete example::
114114 if event in ('call', 'line', 'exception'):
115115 return trace_function
116116 return None
117-
118-
117+
118+
119119 def channel_cb(channel, tasklet, sending, willblock):
120120 tf = tasklet.trace_function
121121 try:
@@ -124,8 +124,8 @@ a complete example::
124124 (tasklet, ("recv", "send")[sending], ("", " will block")[willblock]))
125125 finally:
126126 tasklet.trace_function = tf
127-
128-
127+
128+
129129 def schedule_cb(prev, next):
130130 # During a tasklet switch (during the execution of this function) the
131131 # the result of stackless.getcurrent() is implementation defined.
@@ -140,20 +140,20 @@ a complete example::
140140 f_back = current_frame.f_back
141141 if f_back is not None:
142142 current_tf = f_back.f_trace
143-
143+
144144 current_info = "Schedule CB "
145145 if not prev:
146146 print("%sstarting %r" % (current_info, next))
147147 elif not next:
148148 print("%sending %r" % (current_info, prev))
149149 else:
150150 print("%sjumping from %s to %s" % (current_info, prev, next))
151-
151+
152152 # Inform about the installed trace functions
153153 prev_tf = current_tf if prev.frame is current_frame else prev.trace_function
154154 next_tf = current_tf if next.frame is current_frame else next.trace_function
155155 print(" Current trace functions: prev: %r, next: %r" % (prev_tf, next_tf))
156-
156+
157157 # Eventually set a trace function
158158 if next is not None:
159159 if not next.is_main:
@@ -175,20 +175,20 @@ a complete example::
175175 traceback.print_exc()
176176 finally:
177177 sys.settrace(current_tf)
178-
178+
179179 if __name__ == "__main__":
180180 if len(sys.argv) > 1 and sys.argv[1] == 'hard':
181181 stackless.enable_softswitch(False)
182-
182+
183183 stackless.set_channel_callback(channel_cb)
184184 stackless.set_schedule_callback(schedule_cb)
185-
185+
186186 NamedTasklet(task, "tick")()
187187 NamedTasklet(task, "trick")()
188188 NamedTasklet(task, "track")()
189-
189+
190190 stackless.run()
191-
191+
192192 stackless.set_channel_callback(None)
193193 stackless.set_schedule_callback(None)
194194
@@ -199,13 +199,13 @@ a complete example::
199199
200200.. note ::
201201
202- This section is out dated and only of historical interest. Since the
203- implementation of :attr: `~tasklet.trace_function ` and
202+ This section is out dated and only of historical interest. Since the
203+ implementation of :attr: `~tasklet.trace_function ` and
204204 :attr: `~tasklet.profile_function ` a debugger can enable tracing or profiling
205205 within the schedule callback without monkey patching.
206-
206+
207207In order to get debugging support working on a per-tasklet basis, you need to
208- ensure you call :func: `sys.settrace ` for all tasklets. Vilhelm Saevarsson
208+ ensure you call :func: `sys.settrace ` for all tasklets. Vilhelm Saevarsson
209209`has an email
210210<http://www.stackless.com/pipermail/stackless/2007-October/003074.html> `_
211211giving code and a description of the steps required including potentially
@@ -215,7 +215,7 @@ Vilhelm's code::
215215
216216 import sys
217217 import stackless
218-
218+
219219 def contextDispatch( prev, next ):
220220 if not prev: #Creating next
221221 # I never see this print out
@@ -232,7 +232,7 @@ Vilhelm's code::
232232 if not next.frame.f_trace:
233233 # We might already be tracing so ...
234234 sys.call_tracing(next.settrace, (traceDispatch, ))
235-
235+
236236 stackless.set_schedule_callback(contextDispatch)
237237
238238 def __call__(self, *args, **kwargs):
@@ -243,11 +243,11 @@ Vilhelm's code::
243243 sys.settrace(None)
244244 self.tempval = new_f
245245 stackless.tasklet.setup(self, f, args, kwargs)
246-
246+
247247 def settrace( self, tb ):
248248 self.frame.f_trace = tb
249249 sys.settrace(tb)
250-
250+
251251 stackless.tasklet.__call__ = __call__
252252 stackless.tasklet.settrace = settrace
253253
0 commit comments