@@ -173,7 +173,11 @@ always available.
173
173
174
174
Call ``func(*args) ``, while tracing is enabled. The tracing state is saved,
175
175
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.
177
181
178
182
179
183
.. data :: copyright
@@ -1471,13 +1475,16 @@ always available.
1471
1475
its return value is not used, so it can simply return ``None ``. Error in the profile
1472
1476
function will cause itself unset.
1473
1477
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
+
1474
1483
Profile functions should have three arguments: *frame *, *event *, and
1475
1484
*arg *. *frame * is the current stack frame. *event * is a string: ``'call' ``,
1476
1485
``'return' ``, ``'c_call' ``, ``'c_return' ``, or ``'c_exception' ``. *arg * depends
1477
1486
on the event type.
1478
1487
1479
- .. audit-event :: sys.setprofile "" sys.setprofile
1480
-
1481
1488
The events have the following meaning:
1482
1489
1483
1490
``'call' ``
@@ -1499,6 +1506,9 @@ always available.
1499
1506
``'c_exception' ``
1500
1507
A C function has raised an exception. *arg * is the C function object.
1501
1508
1509
+ .. audit-event :: sys.setprofile "" sys.setprofile
1510
+
1511
+
1502
1512
.. function :: setrecursionlimit(limit)
1503
1513
1504
1514
Set the maximum depth of the Python interpreter stack to *limit *. This limit
@@ -1558,6 +1568,10 @@ always available.
1558
1568
If there is any error occurred in the trace function, it will be unset, just
1559
1569
like ``settrace(None) `` is called.
1560
1570
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
+
1561
1575
The events have the following meaning:
1562
1576
1563
1577
``'call' ``
0 commit comments