Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 0d490e1

Browse files
author
Anselm Kruis
committed
Cleanup white-space. No changes to the text.
1 parent 4599c9c commit 0d490e1

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

Doc/library/stackless/tasklets.rst

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ currently executing.
4343
Example - is the main tasklet the current tasklet::
4444

4545
stackless.main == stackless.current
46-
46+
4747
Example - is the current tasklet the main tasklet::
4848

4949
stackless.current.is_main == 1
@@ -68,13 +68,13 @@ The ``tasklet`` class
6868
This class exposes the form of lightweight thread (the tasklet) provided by
6969
|SLP|. Wrapping a callable object and arguments to pass into
7070
it when it is invoked, the callable is run within the tasklet.
71-
71+
7272
Tasklets are usually created in the following manner::
73-
73+
7474
>>> stackless.tasklet(func)(1, 2, 3, name="test")
75-
75+
7676
The above code is equivalent to::
77-
77+
7878
>>> t = stackless.tasklet()
7979
>>> t.bind(func)
8080
>>> t.setup(1, 2, 3, name="test")
@@ -90,7 +90,7 @@ The ``tasklet`` class
9090

9191
Note that when an implicit :meth:`tasklet.insert` is invoked, there is no need
9292
to hold a reference to the created tasklet.
93-
93+
9494
.. method:: tasklet.bind(func=None, args=None, kwargs=None)
9595

9696
Bind the tasklet to the given callable object, *func*::
@@ -111,10 +111,10 @@ The ``tasklet`` class
111111

112112
*func* can be None when providing arguments, in which case a previous call
113113
to :meth:`tasklet.bind` must have provided the function.
114-
114+
115115
To clear the binding of a tasklet set all arguments to ``None``. This
116116
is especially useful, if you run a tasklet only partially::
117-
117+
118118
>>> def func():
119119
... try:
120120
... ... # part 1
@@ -125,10 +125,10 @@ The ``tasklet`` class
125125
>>> t = stackless.tasklet(func)()
126126
>>> stackless.enable_softswitch(True)
127127
>>> stackless.run() # execute part 1 of func
128-
>>> t.bind(None) # unbind func(). Don't execute the finally block
129-
128+
>>> t.bind(None) # unbind func(). Don't execute the finally block
129+
130130
If a tasklet is alive, it can be rebound only if the tasklet is
131-
not the current tasklet and if the tasklet is not scheduled and
131+
not the current tasklet and if the tasklet is not scheduled and
132132
if the tasklet is restorable. :meth:`bind` raises :exc:`RuntimeError`,
133133
if these conditions are not met.
134134

@@ -139,12 +139,12 @@ The ``tasklet`` class
139139
>>> t = stackless.tasklet()
140140
>>> t.bind(func)
141141
>>> t.setup(1, 2, name="test")
142-
142+
143143
In most every case, programmers will instead pass the arguments and
144144
callable into the tasklet constructor instead::
145145

146146
>>> t = stackless.tasklet(func)(1, 2, name="test")
147-
147+
148148
Note that when tasklets have been bound to a callable object and
149149
provided with arguments to pass to it, they are implicitly
150150
scheduled and will be run in turn when the scheduler is next run.
@@ -168,9 +168,9 @@ The ``tasklet`` class
168168
.. method:: tasklet.remove()
169169

170170
Remove a tasklet from the runnables queue.
171-
171+
172172
.. note::
173-
173+
174174
If this tasklet has a non-trivial C-state attached, Stackless
175175
will kill the tasklet when the containing thread terminates.
176176
Since this will happen in some unpredictable order, it may cause unwanted
@@ -182,9 +182,9 @@ The ``tasklet`` class
182182
If the tasklet is alive and not blocked on a channel, then it will be run
183183
immediately. However, this behaves differently depending on whether
184184
the tasklet is in the scheduler's chain of runnable tasklets.
185-
185+
186186
Example - running a tasklet that is scheduled::
187-
187+
188188
>>> def f(name):
189189
... while True:
190190
... c=stackless.current
@@ -206,7 +206,7 @@ The ``tasklet`` class
206206
yields, the next tasklet in the chain is scheduled and so forth until the
207207
tasklet that actually ran *t1* - that is the main tasklet - is scheduled and
208208
resumes execution.
209-
209+
210210
If you were to run *t2* instead of *t1*, then we would have only seen the
211211
output of *t2* and *t3*, because the tasklet calling :attr:`run` is before
212212
*t1* in the chain.
@@ -226,7 +226,7 @@ The ``tasklet`` class
226226
t2 id=36355504, next.id=36356016, main.id=36356016, main.scheduled=True
227227
>>> t2.scheduled
228228
True
229-
229+
230230
While the ability to run a tasklet directly is useful on occasion, that
231231
the scheduler is still involved and that this is merely directing its
232232
operation in limited ways, is something you need to be aware of.
@@ -238,10 +238,10 @@ The ``tasklet`` class
238238
the scheduling queue.
239239

240240
The target tasklet must belong to the same thread as the caller.
241-
242-
Example - switch to a tasklet that is scheduled. Function f is defined as
241+
242+
Example - switch to a tasklet that is scheduled. Function f is defined as
243243
in the previous example::
244-
244+
245245
>>> t1 = stackless.tasklet(f)("t1")
246246
>>> t2 = stackless.tasklet(f)("t2")
247247
>>> t3 = stackless.tasklet(f)("t3")
@@ -259,16 +259,16 @@ The ``tasklet`` class
259259
File "<stdin>", line 6, in f
260260
KeyboardInterrupt
261261
>>>
262-
263-
What you see here is that the main tasklet was removed from the scheduler.
262+
263+
What you see here is that the main tasklet was removed from the scheduler.
264264
Therefore the scheduler runs until it got interrupted by a keyboard interrupt.
265265

266266
.. method:: tasklet.raise_exception(exc_class, *args)
267267

268268
Raise an exception on the given tasklet. *exc_class* is required to be a
269269
sub-class of :exc:`Exception`. It is instantiated with the given arguments
270270
*args* and raised within the given tasklet.
271-
271+
272272
In order to make best use of this function, you should be familiar with
273273
how tasklets and the scheduler :ref:`deal with exceptions
274274
<slp-exc-section>`, and the purpose of the :ref:`TaskletExit <slp-exc>`
@@ -312,7 +312,7 @@ The ``tasklet`` class
312312
.. method:: tasklet.set_atomic(flag)
313313

314314
This method is used to construct a block of code within which the tasklet
315-
will not be auto-scheduled when preemptive scheduling. It is useful for
315+
will not be auto-scheduled when preemptive scheduling. It is useful for
316316
wrapping critical sections that should not be interrupted::
317317

318318
old_value = t.set_atomic(1)
@@ -353,8 +353,8 @@ The following (read-only) attributes allow tasklet state to be checked:
353353
.. attribute:: tasklet.paused
354354

355355
This attribute is ``True`` when a tasklet is alive, but not scheduled or
356-
blocked on a channel. This state is entered after a :meth:`tasklet.bind` with
357-
2 or 3 arguments, a :meth:`tasklet.remove` or by the main tasklet, when it
356+
blocked on a channel. This state is entered after a :meth:`tasklet.bind` with
357+
2 or 3 arguments, a :meth:`tasklet.remove` or by the main tasklet, when it
358358
is acting as a watchdog.
359359

360360
.. attribute:: tasklet.blocked
@@ -368,11 +368,11 @@ The following (read-only) attributes allow tasklet state to be checked:
368368

369369
.. attribute:: tasklet.restorable
370370

371-
This attribute is ``True``, if the tasklet can be completely restored by
372-
pickling/unpickling. If a tasklet is restorable, it is possible to continue
371+
This attribute is ``True``, if the tasklet can be completely restored by
372+
pickling/unpickling. If a tasklet is restorable, it is possible to continue
373373
running the unpickled tasklet from whatever point in execution it may be.
374-
375-
All tasklets can be pickled for debugging/inspection
374+
375+
All tasklets can be pickled for debugging/inspection
376376
purposes, but an unpickled tasklet might have lost runtime information (C stack).
377377
For the tasklet to be runnable, it must not have lost runtime information
378378
(C stack usage for instance).
@@ -416,12 +416,12 @@ The following attributes allow identification of tasklet place:
416416
import stackless
417417
def is_current_main(tasklet):
418418
return tasklet is stackless.main
419-
419+
420420
.. attribute:: tasklet.thread_id
421421

422422
This attribute is the id of the thread the tasklet belongs to. If its
423423
thread has terminated, the attribute value is ``-1``.
424-
424+
425425
The relationship between tasklets and threads is :doc:`covered elsewhere
426426
<threads>`.
427427

@@ -439,16 +439,16 @@ The following attributes allow a tasklets place in a chain to be identified:
439439

440440
The next tasklet in the chain that this tasklet is linked into.
441441

442-
The following attributes are intended only for implementing debuggers,
443-
profilers, coverage tools and the like. Their behavior is part of the
444-
implementation platform, rather than part of the language definition,
442+
The following attributes are intended only for implementing debuggers,
443+
profilers, coverage tools and the like. Their behavior is part of the
444+
implementation platform, rather than part of the language definition,
445445
and thus may not be available in all |SLP| implementations.
446446

447447
.. attribute:: tasklet.trace_function
448448

449449
.. attribute:: tasklet.profile_function
450450

451-
The trace / profile function of the tasklet. These attributes
451+
The trace / profile function of the tasklet. These attributes
452452
are the tasklet counterparts of the functions :func:`sys.settrace`,
453453
:func:`sys.gettrace`, :func:`sys.setprofile` and :func:`sys.getprofile`.
454454

@@ -457,16 +457,16 @@ and thus may not be available in all |SLP| implementations.
457457
Tasklet Life Cycle
458458
^^^^^^^^^^^^^^^^^^
459459

460-
Here is a somewhat simplified state chart that shows the life cycle of a
461-
tasklet instance. The chart does not show the nesting-level, the thread-id
462-
and the flags atomic, ignore-nesting, block-trap and restorable.
460+
Here is a somewhat simplified state chart that shows the life cycle of a
461+
tasklet instance. The chart does not show the nesting-level, the thread-id
462+
and the flags atomic, ignore-nesting, block-trap and restorable.
463463

464464
.. image:: tasklet_state_chart.png
465465

466-
Furthermore the diagram does not show the scheduler functions
467-
:func:`stackless.run`, :func:`stackless.schedule` and
468-
:func:`stackless.schedule_remove()`. For the purpose of understanding the
469-
state transitions these functions are roughly equivalent to the following
466+
Furthermore the diagram does not show the scheduler functions
467+
:func:`stackless.run`, :func:`stackless.schedule` and
468+
:func:`stackless.schedule_remove()`. For the purpose of understanding the
469+
state transitions these functions are roughly equivalent to the following
470470
|PY| definitions::
471471

472472
def run():
@@ -476,9 +476,9 @@ state transitions these functions are roughly equivalent to the following
476476
stackless.current.next.run()
477477
main.switch()
478478
stackless.tasklet(watchdog)().switch()
479-
479+
480480
def schedule():
481481
stackless.current.next.run()
482-
482+
483483
def schedule_remove():
484484
stackless.current.next.switch()

0 commit comments

Comments
 (0)