Skip to content

Commit cbbad95

Browse files
author
Anselm Kruis
committed
Stackless issue python#36: documentation updates
- Update the C-API docs to match stackless_api.h - Add the Stackless C-API documentation to the TOC-tree. - fix broken links to external locations - Add Anselm Kruis to the list of maintainers. https://bitbucket.org/stackless-dev/stackless/issues/36 (grafted from f5b236f83d72 and 1896b9fd070901be01e6fc466fc1f9fa520b9c1d)
1 parent 021f08c commit cbbad95

File tree

2 files changed

+69
-37
lines changed

2 files changed

+69
-37
lines changed

Doc/c-api/stackless.rst

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
.. highlightlang:: c
22

3-
.. comment: affected files: data\refcounts.dat
4-
.. comment: affected files: c-api\stackless.rst
5-
.. comment: to do: link c-api\stackless.rst in somewhere
6-
.. comment: to do: generate new docs
3+
|SLP| C-API
4+
===========
5+
6+
|SLP| provides the following C functions.
77

88
Tasklets
99
--------
@@ -18,7 +18,7 @@ Tasklets
1818
exception is set, which is in contrast elsewhere in the function.
1919
2020
.. c:function:: int PyTasklet_Setup(PyTaskletObject *task, PyObject *args, PyObject *kwds)
21-
21+
2222
Binds a tasklet function to parameters, making it ready to run and inserts in
2323
into the runnables queue. Returns ``0`` if successful or ``-1`` in the case of failure.
2424
@@ -33,6 +33,19 @@ Tasklets
3333
the call soft switched, ``0`` if the call hard switched and -1 in the case of
3434
failure.
3535
36+
.. c:function:: int PyTasklet_Switch(PyTaskletObject *task)
37+
38+
Forces *task* to run immediately. The previous tasklet is paused.
39+
Returns ``0`` if successful, and ``-1`` in the
40+
case of failure.
41+
42+
.. c:function:: int PyTasklet_Switch_nr(PyTaskletObject *task)
43+
44+
Forces *task* to run immediately, soft switching if possible.
45+
The previous tasklet is paused. Returns ``1`` if
46+
the call soft switched, ``0`` if the call hard switched and -1 in the case of
47+
failure.
48+
3649
.. c:function:: int PyTasklet_Remove(PyTaskletObject *task)
3750
3851
Removes *task* from the runnables queue. Be careful! If this tasklet has a C
@@ -45,41 +58,35 @@ Tasklets
4558
Insert *task* into the runnables queue, if it isn't already there. If it is
4659
blocked or dead, the function returns ``-1`` and a :exc:`RuntimeError` is raised.
4760
48-
.. c:function:: PyObject *PyTasklet_Become(PyTaskletObject *self, PyObject *retval)
49-
50-
Use of this API function is undocumented and unrecommended.
51-
52-
.. deprecated:: 2.5
53-
Proved problematic in production use and are pending removal.
54-
55-
.. c:function:: PyObject* PyTasklet_Capture(PyTaskletObject *self, PyObject *retval)
56-
57-
Use of this API function is undocumented and unrecommended.
58-
59-
.. deprecated:: 2.5
60-
Proved problematic in production use and are pending removal.
61-
6261
.. c:function:: int PyTasklet_RaiseException(PyTaskletObject *self, PyObject *klass, PyObject *args)
6362
6463
Raises an instance of the *klass* exception on the *self* tasklet. *klass* must
6564
be a subclass of :exc:`Exception`. Returns ``1`` if the call soft switched, ``0``
6665
if the call hard switched and ``-1`` in the case of failure.
6766
6867
.. note:: Raising :exc:`TaskletExit` on a tasklet can be done to silently kill
69-
it, see :c:func:`PyTasklet_Kill`.
68+
it, see :c:func:`PyTasklet_Kill`.
69+
70+
.. c:function:: int PyTasklet_Throw(PyTaskletObject *self, int pending, PyObject *exc, PyObject *val, PyObject *tb)
71+
72+
Raises (*exc*, *val*, *tb*) on the *self* tasklet. This is the C equivalent to
73+
method :py:meth:`tasklet.throw`. Returns ``1`` if the call soft switched, ``0``
74+
if the call hard switched and ``-1`` in the case of failure.
7075
7176
.. c:function:: int PyTasklet_Kill(PyTaskletObject *self)
72-
77+
7378
Raises :exc:`TaskletExit` on tasklet *self*. This should result in *task* being
74-
silently killed. Returns ``1`` if the call soft switched, ``0`` if the call hard
79+
silently killed. (This exception is ignored by tasklet_end and
80+
does not invoke main as exception handler.)
81+
Returns ``1`` if the call soft switched, ``0`` if the call hard
7582
switched and ``-1`` in the case of failure.
7683
7784
.. c:function:: int PyTasklet_GetAtomic(PyTaskletObject *task)
7885
7986
Returns ``1`` if *task* is atomic, otherwise ``0``.
8087
8188
.. c:function:: int PyTasklet_SetAtomic(PyTaskletObject *task, int flag)
82-
89+
8390
Returns ``1`` if *task* is currently atomic, otherwise ``0``. Sets the
8491
atomic attribute to the logical value of *flag*.
8592
@@ -129,7 +136,7 @@ Tasklets
129136
130137
Returns ``1`` if *task* is alive (has an associated frame), otherwise
131138
``0`` if it is dead.
132-
139+
133140
.. c:function:: int PyTasklet_Paused(PyTaskletObject *task)
134141
135142
Returns ``1`` if *task* is paused, otherwise ``0``. A tasklet is paused if it is
@@ -151,7 +158,7 @@ Tasklets
151158
Channels
152159
--------
153160
154-
.. c:function:: PyChannelObject* PyChannel_New(PyTypeObject *type)
161+
.. c:function:: PyChannelObject* PyChannel_New(PyTypeObject *type)
155162
156163
Return a new channel object, or *NULL* in the case of failure. *type* must be
157164
derived from :c:type:`PyChannel_Type` or be *NULL*, otherwise a :exc:`TypeError`
@@ -184,6 +191,11 @@ Channels
184191
Returns ``0`` if successful or ``-1`` in the case of failure. An instance of the
185192
exception type *klass* is raised on the first tasklet blocked on channel *self*.
186193
194+
.. c:function:: int PyChannel_SendThrow(PyChannelObject *self, PyObject *exc, PyObject *val, PyObject *tb)
195+
196+
Returns ``0`` if successful or ``-1`` in the case of failure.
197+
(*exc*, *val*, *tb*) is raised on the first tasklet blocked on channel *self*.
198+
187199
.. c:function:: PyObject *PyChannel_GetQueue(PyChannelObject *self)
188200
189201
Returns the first tasklet in the channel *self*'s queue, or *NULL* in the case
@@ -255,6 +267,23 @@ stackless module
255267
256268
Get the currently running tasklet, that is, "yourself".
257269
270+
.. c:function:: long PyStackless_GetCurrentId()
271+
272+
Get a unique integer ID for the current tasklet
273+
274+
Threadsafe.
275+
276+
This is useful for benchmarking code that
277+
needs to get some sort of a stack identifier and must
278+
not worry about the GIL being present and so on.
279+
280+
.. note::
281+
282+
1. the "main" tasklet on each thread will have the same id,
283+
even if a proper tasklet has not been initialized.
284+
285+
2. IDs may get recycled for new tasklets.
286+
258287
.. c:function:: PyObject *PyStackless_RunWatchdog(long timeout)
259288
260289
Runs the scheduler until there are no tasklets remaining within it, or until
@@ -274,28 +303,28 @@ stackless module
274303
Wraps :c:func:`PyStackless_RunWatchdog`, but allows its behaviour to be
275304
customised by the value of *flags* which may contain any of the following
276305
bits:
277-
306+
278307
``Py_WATCHDOG_THREADBLOCK``
279308
Allows a thread to block if it runs out of tasklets. Ideally
280309
it will be awakened by other threads using channels which its
281310
blocked tasklets are waiting on.
282-
311+
283312
``Py_WATCHDOG_SOFT``
284313
Instead of interrupting a tasklet, we wait until the
285314
next tasklet scheduling moment to return. Always returns
286315
*Py_None*, as everything is in order.
287-
316+
288317
``Py_WATCHDOG_IGNORE_NESTING``
289318
Allows interrupts at all levels, effectively acting as
290319
though the *ignore_nesting* attribute were set on all
291320
tasklets.
292-
321+
293322
``Py_WATCHDOG_TIMEOUT``
294323
Interprets *timeout* as a fixed run time, rather than a
295324
per-tasklet run limit. The function will then attempt to
296325
interrupt execution once this many total opcodes have
297326
been executed since the call was made.
298-
327+
299328
debugging and monitoring functions
300329
----------------------------------
301330

Doc/stackless-python.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ through the :mod:`stackless` module.
3232
:maxdepth: 3
3333

3434
library/stackless/stackless.rst
35+
c-api/stackless.rst
3536

3637
.. I'd really like the "What you need to know", "External resources" and
3738
.. "History" sections to appear in the table of contents.. but this does
@@ -58,7 +59,7 @@ and writing, socket operations, interprocess communication and more), although
5859
asynchronous versions of IO functionality.
5960

6061
Some third-party modules are available that replace standard library
61-
functionality with Stackless-compatible versions. The advantage of this
62+
functionality with Stackless-compatible versions. The advantage of this
6263
approach is that other modules which use that standard functionality,
6364
also work with Stackless when the replacement is installed. The
6465
`Stackless socket
@@ -94,11 +95,12 @@ documentation <library/stackless/debugging>`.
9495
External resources
9596
==================
9697

97-
There are a range of resources available outside of this document:
98+
There are a range of resources available outside of this document. However most of them are
99+
nowadays quite dated:
98100

99101
* The Stackless `mailing list <http://www.stackless.com/mailman/listinfo/stackless>`_.
100-
* The Stackless `examples project <http://code.google.com/p/stacklessexamples>`_.
101-
* Grant Olson's tutorial: `Introduction to Concurrent Programming with Stackless Python <http://www.grant-olson.net/python/intro-to-stackless-python>`_.
102+
* The Stackless `examples project <https://bitbucket.org/stackless-dev/stacklessexamples>`_.
103+
* Grant Olson's tutorial: `Introduction to Concurrent Programming with Stackless Python <http://www.grant-olson.net/projects/introduction-to-stackless-python.html>`_.
102104

103105
History
104106
=======
@@ -154,14 +156,15 @@ Richard Tew to PyCon where `they sprinted
154156
<http://zope.stackless.com/Members/rmtew/News%20Archive/pycon2006/news_item_view>`_
155157
with the aid of Christian Tismer. The result was an up to date release of |SLP|.
156158
From this point in time, maintaining and releasing |SLP|
157-
has been undertaken by Richard and Kristján.
159+
has been undertaken by Richard and Kristján. A few years later Anselm Kruis
160+
joined the team.
158161

159162
.. [#PSFTRADEMARK]
160-
"Python" and the Python logos are trademarks or registered trademarks of the
163+
"Python" and the Python logos are trademarks or registered trademarks of the
161164
*Python Software Foundation*, used by |SLP| with permission from the Foundation.
162165
See http://www.python.org/psf/trademarks/ for details.
163166
164167
.. [#CPY]
165-
With the term "|CPY|" we refer to the reference implementation of the |PPL|
168+
With the term "|CPY|" we refer to the reference implementation of the |PPL|
166169
that is released by the *Python Software Foundation* on http://www.python.org.
167170

0 commit comments

Comments
 (0)