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