@@ -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
@@ -1439,13 +1443,16 @@ always available.
1439
1443
its return value is not used, so it can simply return ``None ``. Error in the profile
1440
1444
function will cause itself unset.
1441
1445
1446
+ .. note ::
1447
+ The same tracing mechanism is used for :func: `!setprofile ` as :func: `settrace `.
1448
+ To trace calls with :func: `!setprofile ` inside a tracing function
1449
+ (e.g. in a debugger breakpoint), see :func: `call_tracing `.
1450
+
1442
1451
Profile functions should have three arguments: *frame *, *event *, and
1443
1452
*arg *. *frame * is the current stack frame. *event * is a string: ``'call' ``,
1444
1453
``'return' ``, ``'c_call' ``, ``'c_return' ``, or ``'c_exception' ``. *arg * depends
1445
1454
on the event type.
1446
1455
1447
- .. audit-event :: sys.setprofile "" sys.setprofile
1448
-
1449
1456
The events have the following meaning:
1450
1457
1451
1458
``'call' ``
@@ -1467,6 +1474,9 @@ always available.
1467
1474
``'c_exception' ``
1468
1475
A C function has raised an exception. *arg * is the C function object.
1469
1476
1477
+ .. audit-event :: sys.setprofile "" sys.setprofile
1478
+
1479
+
1470
1480
.. function :: setrecursionlimit(limit)
1471
1481
1472
1482
Set the maximum depth of the Python interpreter stack to *limit *. This limit
@@ -1526,6 +1536,10 @@ always available.
1526
1536
If there is any error occurred in the trace function, it will be unset, just
1527
1537
like ``settrace(None) `` is called.
1528
1538
1539
+ .. note ::
1540
+ Tracing is disabled while calling the trace function (e.g. a function set by
1541
+ :func: `!settrace `). For recursive tracing see :func: `call_tracing `.
1542
+
1529
1543
The events have the following meaning:
1530
1544
1531
1545
``'call' ``
0 commit comments