Skip to content

Commit b1da634

Browse files
miss-islingtonimpact27CAM-Gerlach
authored
[3.12] gh-102249: Expand sys.call_tracing documentation (GH-102806) (#111557)
Co-authored-by: Quentin Peter <[email protected]> Co-authored-by: C.A.M. Gerlach <[email protected]>
1 parent 71e138d commit b1da634

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

Doc/library/sys.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ always available.
173173

174174
Call ``func(*args)``, while tracing is enabled. The tracing state is saved,
175175
and restored afterwards. This is intended to be called from a debugger from
176-
a checkpoint, to recursively debug some other code.
176+
a checkpoint, to recursively debug or profile some other code.
177+
178+
Tracing is suspended while calling a tracing function set by
179+
:func:`settrace` or :func:`setprofile` to avoid infinite recursion.
180+
:func:`!call_tracing` enables explicit recursion of the tracing function.
177181

178182

179183
.. data:: copyright
@@ -1471,13 +1475,16 @@ always available.
14711475
its return value is not used, so it can simply return ``None``. Error in the profile
14721476
function will cause itself unset.
14731477

1478+
.. note::
1479+
The same tracing mechanism is used for :func:`!setprofile` as :func:`settrace`.
1480+
To trace calls with :func:`!setprofile` inside a tracing function
1481+
(e.g. in a debugger breakpoint), see :func:`call_tracing`.
1482+
14741483
Profile functions should have three arguments: *frame*, *event*, and
14751484
*arg*. *frame* is the current stack frame. *event* is a string: ``'call'``,
14761485
``'return'``, ``'c_call'``, ``'c_return'``, or ``'c_exception'``. *arg* depends
14771486
on the event type.
14781487

1479-
.. audit-event:: sys.setprofile "" sys.setprofile
1480-
14811488
The events have the following meaning:
14821489

14831490
``'call'``
@@ -1499,6 +1506,9 @@ always available.
14991506
``'c_exception'``
15001507
A C function has raised an exception. *arg* is the C function object.
15011508

1509+
.. audit-event:: sys.setprofile "" sys.setprofile
1510+
1511+
15021512
.. function:: setrecursionlimit(limit)
15031513

15041514
Set the maximum depth of the Python interpreter stack to *limit*. This limit
@@ -1558,6 +1568,10 @@ always available.
15581568
If there is any error occurred in the trace function, it will be unset, just
15591569
like ``settrace(None)`` is called.
15601570

1571+
.. note::
1572+
Tracing is disabled while calling the trace function (e.g. a function set by
1573+
:func:`!settrace`). For recursive tracing see :func:`call_tracing`.
1574+
15611575
The events have the following meaning:
15621576

15631577
``'call'``

0 commit comments

Comments
 (0)