Skip to content

Commit 3aa8f75

Browse files
impact27CAM-Gerlach
authored andcommitted
pythongh-102249: Expand sys.call_tracing documentation (python#102806)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
1 parent 62a924e commit 3aa8f75

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

Doc/library/sys.rst

+17-3
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ always available.
175175

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

180184

181185
.. data:: copyright
@@ -1473,13 +1477,16 @@ always available.
14731477
its return value is not used, so it can simply return ``None``. Error in the profile
14741478
function will cause itself unset.
14751479

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

1481-
.. audit-event:: sys.setprofile "" sys.setprofile
1482-
14831490
The events have the following meaning:
14841491

14851492
``'call'``
@@ -1501,6 +1508,9 @@ always available.
15011508
``'c_exception'``
15021509
A C function has raised an exception. *arg* is the C function object.
15031510

1511+
.. audit-event:: sys.setprofile "" sys.setprofile
1512+
1513+
15041514
.. function:: setrecursionlimit(limit)
15051515

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

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

15651579
``'call'``

0 commit comments

Comments
 (0)